Is it possible to make a WinRT service

2019-03-30 01:31发布

问题:

Since WinRT have unique capabilities, I wonder if it were to make a Windows Service that is targeted to WinRT? If it were not possible, is the workaround to make an invisible WinRT/Metro application possible?

Thanks a lot.

回答1:

No is the correct answer. A metro application executes inside the Metro shell and inside an execution container that creates a sandbox away from system resources, including services. For this reason a metro app cannot access a local service. Similarly, for this reason, a metro app cannot be a service.

Background tasks and push notifications through Windows Notification Services are the only way for a metro app to interact with the user while not active. Otherwise, when the application is not active (not visible), all of its threads are suspended (unlike a service).

As for background tasks, their activity is constrained identically to a metro app and limited to a single CPU second every 2 hours (there is one exception). Push notifications can execute more frequently, but are only capable of updating a tile or raising a toast notification.

The intent of a metro application is different than a traditional desktop application:

Metro applications are architecture independent (run on intel or arm). Metro applications are touch-reach, built for touch screens. Metro applications are fully hardware accelerated. Metro applications leverage the next gen hardware that certified devices offer, including unprecedented battery life. Metro applications are the only applications delivered by the Windows store.

Look, choosing a metro application does mean to concede some of the unlimited power of desktop applications. However, the gains are significant, too.



回答2:

Nope this isn't possible (wither the service, or the "invisible" metro application).

You can run background tasks that may do what you are after, but without understanding your problem I couldn't say.



回答3:

It depends on what you want to do.

WinRT is an API and can be accessed from Metro (Windows Store) Apps and from Desktop/C# apps.

However not the full API is exposed - see what you are allowed to access here: http://msdn.microsoft.com/en-us/library/windows/desktop/hh920511%28v=vs.85%29.aspx

Hanselman shows how to add a ref to WinRT:

  • Edit the csproj:
<PropertyGroup>
  <TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>
  • Then add a reference to Core/Windows.

http://www.hanselman.com/blog/HowToCallWinRTAPIsInWindows8FromCDesktopApplicationsWinRTDiagram.aspx