Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How To Use Windows Runtime Component in WinForm App

How To Use Windows Runtime Component in WinForm App

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Django_Untaken
    wrote on last edited by
    #1

    Hello. I have this backgroundTask whose output type is Windows 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 reference

    public 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

    A 1 Reply Last reply
    0
    • D Django_Untaken

      Hello. I have this backgroundTask whose output type is Windows 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 reference

      public 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

      A Offline
      A Offline
      Afzaal Ahmad Zeeshan
      wrote on last edited by
      #2

      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 !~

      D 1 Reply Last reply
      0
      • A Afzaal Ahmad Zeeshan

        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 !~

        D Offline
        D Offline
        Django_Untaken
        wrote on last edited by
        #3

        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.

        A 1 Reply Last reply
        0
        • D Django_Untaken

          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.

          A Offline
          A Offline
          Afzaal Ahmad Zeeshan
          wrote on last edited by
          #4

          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 !~

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups