How To Use Windows Runtime Component in WinForm App
-
Hello. I have this
backgroundTask
whose output type isWindows Runtime Component
. I have absolutely no idea how to use this backgoundTask in my winform application. Basically this backgroundTask gets geolocation and retrieves long/lat. Here is the skeleton for referencepublic sealed class LocationBackgroundTask : IBackgroundTask
{
async void IBackgroundTask.Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
try
{
/* SOME CODE FOR GETTING LOCATION */
}
catch(Exception ex) { }
finally
{
deferral.Complete();
}
}
}Again, I have no idea how do I use this runtime component from my winform application (a button will invoke this). This code is in one project and my winform application is second project. Thanks for any input
-
Hello. I have this
backgroundTask
whose output type isWindows Runtime Component
. I have absolutely no idea how to use this backgoundTask in my winform application. Basically this backgroundTask gets geolocation and retrieves long/lat. Here is the skeleton for referencepublic sealed class LocationBackgroundTask : IBackgroundTask
{
async void IBackgroundTask.Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
try
{
/* SOME CODE FOR GETTING LOCATION */
}
catch(Exception ex) { }
finally
{
deferral.Complete();
}
}
}Again, I have no idea how do I use this runtime component from my winform application (a button will invoke this). This code is in one project and my winform application is second project. Thanks for any input
Where did you find that code, or API? That requires you to involve Windows Runtime with Windows Forms? Although I am not saying that WinRT and .NET do not go well, they do and that is the beauty of C# itself. But, what I wanted to know was, why would you need to do that, when there are many easy cases? Secondly, if an API does expose these types, then it would also expose some wrapper types, too. Are you a bit confused about the term, "[component](https://msdn.microsoft.com/en-us/library/hh441572.aspx)"? Finally, as I can see, your
IBackgroundTask.Run
function has a void return type — void can be captured in .NET itself, no need for any Windows Runtime component. That looks like the default Windows Runtime background task interface, you should read a bit more about it here, [Background Tasks in Windows Store Apps -- Visual Studio Magazine](https://visualstudiomagazine.com/articles/2013/05/01/background-tasks-in-windows-store-apps.aspx), it shows a good example of handling these background tasks. That will help you understand how it works. Anyways, please do read this by Scott Hanselman as well, [How to call WinRT APIs in Windows 8 from C# Desktop Applications - WinRT Diagram - Scott Hanselman](http://www.hanselman.com/blog/HowToCallWinRTAPIsInWindows8FromCDesktopApplicationsWinRTDiagram.aspx)The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
Where did you find that code, or API? That requires you to involve Windows Runtime with Windows Forms? Although I am not saying that WinRT and .NET do not go well, they do and that is the beauty of C# itself. But, what I wanted to know was, why would you need to do that, when there are many easy cases? Secondly, if an API does expose these types, then it would also expose some wrapper types, too. Are you a bit confused about the term, "[component](https://msdn.microsoft.com/en-us/library/hh441572.aspx)"? Finally, as I can see, your
IBackgroundTask.Run
function has a void return type — void can be captured in .NET itself, no need for any Windows Runtime component. That looks like the default Windows Runtime background task interface, you should read a bit more about it here, [Background Tasks in Windows Store Apps -- Visual Studio Magazine](https://visualstudiomagazine.com/articles/2013/05/01/background-tasks-in-windows-store-apps.aspx), it shows a good example of handling these background tasks. That will help you understand how it works. Anyways, please do read this by Scott Hanselman as well, [How to call WinRT APIs in Windows 8 from C# Desktop Applications - WinRT Diagram - Scott Hanselman](http://www.hanselman.com/blog/HowToCallWinRTAPIsInWindows8FromCDesktopApplicationsWinRTDiagram.aspx)The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
Afzaal Ahmad Zeeshan wrote:
Where did you find that code, or API?
It is a sample I downloaded somewhere on the web.
Afzaal Ahmad Zeeshan wrote:
why would you need to do that, when there are many easy cases?
Can you tell me those easy cases? I do not know.
-
Afzaal Ahmad Zeeshan wrote:
Where did you find that code, or API?
It is a sample I downloaded somewhere on the web.
Afzaal Ahmad Zeeshan wrote:
why would you need to do that, when there are many easy cases?
Can you tell me those easy cases? I do not know.
Django_Untaken wrote:
Can you tell me those easy cases? I do not know.
One of them would be, to not expose the native typing in either of the cases. Use the types that can be used in both the runtimes. Since you are writing a background task handler, there is no need to use Windows Runtime background task handler, you can do that in Windows Forms itself using .NET framework's Task API. Which is much more simpler and easier to use. [Task Class (System.Threading.Tasks)](https://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=vs.110).aspx) Secondly, if you really do require to have a WinRT component, then make sure it exposes the type that .NET can consume natively; such as returning the string values, integer results etc. Since you only provide an interface implementation, it is very hard to tell what you want to do with that code.
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~