Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:07:06+00:00 2026-06-02T08:07:06+00:00

I am porting some C# .Net code to WinRT and I am having trouble

  • 0

I am porting some C# .Net code to WinRT and I am having trouble figuring out how to replace the following:

bool threadDone = false;
Thread updateThread = null;

void StartUpdateThread() {
  threadDone = false;
  updateThread = new Thread(new ThreadStart(SendUpdateThread));
  updateThread.Start();
}

void StopUpdateThread() {
  if (updateThread == null) return;
  threadDone = true;
  updateThread.Join();
  updateThread = null;
}

void SendUpdateThread() {
  while(!threadDone) { 
    ... 
    Thread.Sleep(...);
  }
}

What is the best way to replace this in WinRT. I have looked at ThreadPool.RunAsync(…) to start the code running, but I am not sure of the best wait to stop it and wait for its completion in StopUpdateThread. Also, what do I replace the sleep with in my thread function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:07:09+00:00Added an answer on June 2, 2026 at 8:07 am

    Since we’re talking about C# 5 GUI application, it would be probably best if you didn’t block anything and used Tasks and async–await instead. That could look something like this:

    // I think this field needs to be volatile even in your version
    volatile bool taskDone = false;
    Task updateTask = null;
    
    void StartUpdateTask() {
      taskDone = false;
      updateTask = Task.Run(SendUpdateTask);
    }
    
    async Task StopUpdateTask() {
      if (updateTask == null) return;
      taskDone = true;
      await updateTask;
      updateTask = null;
    }
    
    async Task SendUpdateTask() {
      while (!taskDone) { 
        ... 
        await Task.Delay(…);
      }
    }
    

    But to use this code correctly, you actually need to understand what async–await does, so you should read up about that.

    Also, this might not be exactly what you need, but that’s hard to know based just on the information in your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am porting some C# code over to Java. I am having trouble with
I'm having trouble porting some .NET2-era C# to .NET2-era VB.NET. Specifically, I am trying
I'm porting some code from PHP to .NET (I'm not a PHP developer) and
Just started doing some code porting from .Net CF to Blackberry JDE 4.6.1. But
I'm just porting some code over from .net to Java. I've been using the
I am porting some Core Data code from iPhone to Mac OS X. Problem
I'm porting some code from Python 2 to 3. This is valid code in
I'm porting some crufty C++ Windows-code to Linux, which uses functions called open and
I'm porting some C++ code to C#. Does C# have an equivalent to std::nth_element()
I'm looking at porting some code that uses java.util.concurrent.ConcurrentSkipListSet to an environment where this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.