I'm trying to make an application with an extended boot screen that needs to connect to a server to start the application. Then thereafter, the application will receive and send data in the background.
I am experiencing a problem when compiling my code, Visual displays the error below:
Erreur de validation. error 80080204: App manifest validation error: Line 35, Column 12, Reason: If it is not an audio background task, it is not allowed to have EntryPoint="PhonieMarthaBackground.SocketActivityTask" without ActivatableClassId in windows.activatableClass.inProcessServer. PhonieMartha C:\Users\PhonieMARTHA\source\repos\PhonieMartha\PhonieMartha\bin\x64\Debug\AppxManifest.xml
I don't understand what's wrong with the manifest.
AppxManifest.xml (Short part):
<Applications>
<Application Id="App" Executable="PhonieMartha.exe" EntryPoint="PhonieMartha.App">
<uap:VisualElements DisplayName="PhonieMartha" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="PhonieMartha" BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="lightGray" />
</uap:VisualElements>
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="PhonieMarthaBackground.SocketActivityTask">
<BackgroundTasks>
<Task Type="systemEvent" />
</BackgroundTasks>
</Extension>
</Extensions>
</Application>
ExtendedSplash.xaml.cs:
private const string socketId = "SampleSocket";
private StreamSocket socket = null;
private IBackgroundTaskRegistration task = null;
private const string port = "40404";
private const string adress = "172.16.161.80";
try
{
foreach (var current in BackgroundTaskRegistration.AllTasks)
{
if (current.Value.Name == "PhonieMarthaBackground")
{
task = current.Value;
break;
}
}
// Si il n'y a pas de tâche déjà crée alors, on en crée une nouvelle
if (task == null)
{
var socketTaskBuilder = new BackgroundTaskBuilder();
socketTaskBuilder.Name = "PhonieMarthaBackground";
socketTaskBuilder.TaskEntryPoint = "PhonieMarthaBackground.SocketActivityTask";
var trigger = new SocketActivityTrigger();
socketTaskBuilder.SetTrigger(trigger);
task = socketTaskBuilder.Register();
}
SocketActivityInformation socketInformation;
if (SocketActivityInformation.AllSockets.TryGetValue(socketId, out socketInformation))
{
// Application can take ownership of the socket and make any socket operation
// For sample it is just transfering it back.
socket = socketInformation.StreamSocket;
socket.TransferOwnership(socketId);
socket = null;
Debug.WriteLine("Connecté");
}
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
SocketActivityTask.cs:
namespace PhonieMarthaBackground
{
public sealed class SocketActivityTask : Windows.ApplicationModel.Background.IBackgroundTask
{
private const string socketId = "SampleSocket";
public async void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
try
{
var details = taskInstance.TriggerDetails as SocketActivityTriggerDetails;
var socketInformation = details.SocketInformation;
switch (details.Reason)
{
case SocketActivityTriggerReason.SocketActivity:
var socket = socketInformation.StreamSocket;
DataReader reader = new DataReader(socket.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
await reader.LoadAsync(250);
var dataString = reader.ReadString(reader.UnconsumedBufferLength);
ShowToast(dataString);
socket.TransferOwnership(socketInformation.Id);
break;
case SocketActivityTriggerReason.KeepAliveTimerExpired:
socket = socketInformation.StreamSocket;
DataWriter writer = new DataWriter(socket.OutputStream);
writer.WriteBytes(Encoding.UTF8.GetBytes("Keep alive"));
await writer.StoreAsync();
writer.DetachStream();
writer.Dispose();
socket.TransferOwnership(socketInformation.Id);
break;
case SocketActivityTriggerReason.SocketClosed:
socket = new StreamSocket();
socket.EnableTransferOwnership(taskInstance.Task.TaskId, SocketActivityConnectedStandbyAction.Wake);
if (ApplicationData.Current.LocalSettings.Values["hostname"] == null)
{
break;
}
var hostname = (String)ApplicationData.Current.LocalSettings.Values["hostname"];
var port = (String)ApplicationData.Current.LocalSettings.Values["port"];
await socket.ConnectAsync(new HostName(hostname), port);
socket.TransferOwnership(socketId);
break;
default:
break;
}
deferral.Complete();
}
catch (Exception exception)
{
ShowToast(exception.Message);
deferral.Complete();
}
}
public void ShowToast(string text)
{
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var textNodes = toastXml.GetElementsByTagName("text");
textNodes.First().AppendChild(toastXml.CreateTextNode(text));
var toastNotification = new ToastNotification(toastXml);
toastNotifier.Show(new ToastNotification(toastXml));
}
}
}
I would like to have a connection to the server and be able to send/receive data in the background so that I can perform the necessary actions for the proper functioning of the HMI.