Is it possible to make a WinRT service - c#

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.

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.

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.

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

Related

How to Launch UWP app from Task Scheduler

I have an app that converts UWP InkCanvas drawings into SVG from UWP native ISF. I need to run it daily, and the conversion logic does not work in either Console apps, WPF apps or Windows Forms apps with Ink Canvas - as there appear to be differences between as to how InkCanvas data is serialized on these other platforms.
I'm looking for a way to launch the UWP app on a schedule - so any pointers in that direction are greatly appreciated.
I do understand that using the UWP apps in this way is probably not a recommended scenario - unfortunately I do not have control over the app that produces these drawings initially - but I do need to convert them to SVG.
If your UWP application is registered to a URI schema it's relatively straightforward to do.
For the scheduled task set explorer.exe as the app, and your-app-schema:// as the parameter.
You can check the schemas and registered apps under Settings -> Apps -> Default Apps -> Choose default apps by protocol. For example the Windows Calculator is registered as calculator://.
You can register a protocol for your application (if you develop it) with the instructions here: https://learn.microsoft.com/en-us/windows/uwp/xbox-apps/automate-launching-uwp-apps#protocol-activation

Minimize Windows 8 Store App while tracking location with GPS

I'm working on a metro app and am having trouble finding how not to show the application.
We recently deployed tablets to our field reps, and need to add gps tracking. GPS is much easier to deal with in the metro libs (it's like 4 lines of code vs. unmanaged) so we're hoping to be able to push a metro app instead of spending time coding a winforms/wpf desktop app (the tablets are full version windows, so it's an option if we can't hide a metro app. I feel like it should be possible though as the start screen tiles update automatically without opening the main program).
In WPF, it's fairly simple to make a window invisible. I'm creating the metro app in wpf, but it uses different libs than desktop and I may just not know how to do it.
In desktop programs, it's fairly simple. You do something along the lines of:
<Page
x:Class = xxxxxxxx
..
Visibility="Hidden">
Unfortunately, with metro, the only options I have are collapsed and visible. Collapsed doesn't seem to have any effect, unless it's just because it's not deployed and visual studio shows it anyway...
So basically I'm trying to figure out if there's a way to start the program minimized or hidden so that it doesn't interrupt the field reps every time it takes their location.
If you really want to make a metro app and want it to run "minimised" you will need to look at background task. To start the background task the user would still need to start the app at least once, futhermore background task have limitation how how often and how long they can run. Also there is a lot of constraint on deploying a windows store app if you cannot publish it in the store.
If your goal is to just have access to GPS through C# apis, the GPS is actually one of the winRT api you can use from the desktop, you can find a tutorial on how to access winRT api from the desktop here
Here is the complete list of winRT api accessible from the desktop (You can find Geoposition class among them).
Have you looked into creating a background task that transmits GPS? The background task can run without the app running.
I am not entirely certain you can voluntarily minimize a Windows Store App on a user's behalf. I see nothing in IntelliSense about it, nor have I found anything online or see any app do it.
However, be aware that deploying the app without using the Windows Store -- sideloading -- requires Windows 8 Enterprise edition computers joined to the domain OR Windows 8 Pro with a sideloading key ($30 per key, purchased in packs of at least 100.) Perhaps a WPF app with unmanaged code is worth the money and effort.

Developing a simple Windows system tray desktop app to consume a .NET web service

I'm required to develop a simple Windows system tray desktop app to consume a .NET web service but I'm proficient in PHP, and I have little background in desktop applications. What platform would you advise me to use, preferably with a very low learning curve?
The system tray app will show (in a context menu) a counter of notifications of new events as received from the .NET web service; and will also write all the event logs into a text file.
I'm already thinking Adobe AIR or C# .NET but I want to know if there are any better options that I can learn quickly to develop the app.
Keep it all in .NET. You can easily write a Windows Forms application to display a tray icon and display notifications as and when something happens in the web service (you'd probably need a timer to do the polling).
There are plenty of articles around that will show you how to do this. Here's one to get you started:
http://www.codeproject.com/Articles/290013/Formless-System-Tray-Application
I assume that you have to use WPF and MVVM so it is going to be really awesome app.
And the best example I found is that one
WPF NotifyIcon
http://www.codeproject.com/Articles/36468/WPF-NotifyIcon

Multitargetting to metro and non metro target platform in Windows 8

I am creating a simple metro app. I am also creating non metro version of the same app.
The problem I am facing is that VS is not allowing me to reference normal class libraries into the metro app, and metro class libraries into a normal app.
The differences between Metro and non-metro apps relate to UI, and to some features which are incompatible (eg, FilePicker in metro, and OpenFileDialog in non metro).
How this can be achieved?
The differences are more drastic than you might expect. They are using WinRT as a chance to clean house and remove APIs they don't want to maintain anymore for various reasons. Research "portable class library" which will let you create a dll based on the small intersection of APIs available in the platforms you tell VS to target
Essentially, WinRT is completely separate from the Win32 libraries as Robert Levy mentioned.
In fact, when Windows 8 is being used on ARM devices the Win32 libraries are practically non-existent. Internet Explorer 10 has limited access to them (an Internet browser powered only by WinRT is impractical), but all other metro apps do not.
Metro apps on x86 and x64 also do not have access to Win32, because it is assumed that the same application needs to be compatible with ARM. To reduce complexity Microsoft has essentially said that all metro apps only have access to WinRT. Internet Explorer is an exception to that rule.
What I'm trying to say is this: You'll have to develop both applications separately. Desktop-focused applications reside entirely on the desktop. And metro applications reside only in the metro interface.
Metro UI is not the problem : look "Under the Hood", and you'll discover that the namespaces and the libraries and NOT the same => METRO in NOT another layer above Windows 7 applications.
If you really want to target the 2 environments, create a single class Library with all your business objects, all your databases access, and write two differrents applications call this Library.

Accessing other processes in Win8 Metro-style app

I am trying to build a Windows 8 "metro-style" app that will operate as a "app killer". For those of you who have used Win8 (Tech Preview) you'll notice that once you open a metro-style app you cannot close it (without going into Task Manager and ending the process).
My challenge is that I cannot access 'System.Diagnostics.Process' from my metro-style app, nor do I know if there is an comparable alternative within the WinRT. I also thought of building a separate app that hosts a service for my metro app to interface with, but I'd like to do this with a single app.
Fundamentally, I am looking for a pattern for building Metro-style apps that leverage .NET 4.0 components, specifically to be able to enumerate and kill other processes running on the PC.
CLARIFICATION: I am less concerned with this specific application than I am with access that type of .NET functionality within a Metro-style app
Thanks
To your specific question, this functionality is not available. Apps are not allowed to interact or interfere with other apps.
To answer your more general question, the APIs available to Metro style applications is limited compared to what is available to desktop applications. C# has a subset of the .Net library available, much like Silverlight does. The same is true for C++ where a subset of the desktop Win32/COM APIs are available.
From what I understand (watching Build2011 videos) a Metro App won't be able to do that...
Interaction between processes is severally limited to specific Contracts (the charms on the right: Search, Send-to).
Think Phone, not Desktop.
You might be able to build a non-Metro Win8 app though.
Don't waste too much time on this. I expect that in a beta a close option (perhaps even a charm) will be included. Until then use a keyboard Alt-F4 or the Task Manager
C++:
Window::Current->CoreWindow->Close();
or
Window::Current->Close();
I haven't explored the difference between these two (more precisely, I don't know how CoreWindow differs from Current. I could assume though...
I'm using an Oracle VBox with Win8 on my Win7 machine to develop a C++ Metro App using VS 11. I used both of the above methods. I verified in Task Manager the app was not running on both Win8 and the Simulator.

Categories

Resources