Reputation: 55
I would like to ask for some suggestions on how I can make the following below possible:
Functionality wanted: I want to give users the option to enable and disable the startup setting for a desktop bridge application I am building while the application is running. Ideally, a small Form window will pop up when a button is pressed via a contextmenu giving two options to the user. 'yes' or 'no' buttons being the two options for whether the app should startup automatically at boot time for the next restart of the system.
Technologies being used: I built the app as a winform application and made it into a uwp app via the desktop bridge functionality. I did this because it will eventually be on the windows app store.
References: there is an API that I am referencing which is called StartupTask that I found at this site: https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.startuptask#properties
I already have this in my Package.appxmanifest file:
<Extensions>
<desktop:Extension
Category="windows.startupTask"
Executable="uniqueFolder\myExeFile.exe"
EntryPoint="Windows.FullTrustApplication">
<desktop:StartupTask
TaskId="myAppTaskID"
Enabled="true"
DisplayName="MyAppDisplayName" />
</desktop:Extension>
</Extensions>
I have successfully added these references:
-Windows(Windows.winmd)
-System.Runtime.WindowsRuntime(WindowsRuntime.dll)
-Windows.ApplicationModel.StartupTaskContract
-Windows.Foundation.FoundationContract
I modified the reference for Windows(Windows.winmd) alias to be something else other than 'global' to avoid the compiler error:
StateError The type 'StartupTaskContract' exists in both '...' and '...'.
The following c# code is an attempt to get started with this functionality by trying to get the startuptaskId for the app which unfortunately gives me an error.
C# code:
async void MyFunct()
{
StartupTask startupTask = await StartupTask.GetAsync("myAppTaskID");
}
Compiler error I am currently receiving:
StateError CS1929 'IAsyncOperation<StartupTask>' does not contain a definition for 'GetAwaiter' and the best extension method overload 'WindowsRuntimeSystemExtensions.GetAwaiter(IAsyncAction)' requires a receiver of type 'IAsyncAction'
Lastly, this enablement and disablement functionality should be reflected in the Windows 10 Startup Apps window showing that the app is either ON or OFF.
I have tried multiple different things with no luck. Maybe I am overlooking some things so having an outside perspective would be helpful.
With the app manifest extension code, the app does boot up automatically at system startup.
I am aware that the users can just turn the app on or off via the startup app window or task manager. But this functionality is a requirement for a client.
Any suggestions would be much appreciated.
Thanks for reading~
Upvotes: 1
Views: 1245
Reputation: 944
packages
<package id="Antlr" version="3.4.1.9004" targetFramework="net452" />
<package id="bootstrap" version="3.0.0" targetFramework="net452" />
<package id="jQuery" version="1.10.2" targetFramework="net452" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net452" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net452" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net452" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
<package id="Modernizr" version="2.6.2" targetFramework="net452" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
<package id="Respond" version="1.2.0" targetFramework="net452" />
<package id="WebGrease" version="1.5.2" targetFramework="net452" />
usings
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Rest;
method
void MyFunct()
{
Task.Factory.StartNew(s => StartupTask.GetAsync("myAppTaskID"), this, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).GetAwaiter();
// or
StartupTask.GetAsync("myAppTaskID").wait();
}
Upvotes: 1