473,382 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Why threading doesn't seem concurrent

1
Hi

I'm pretty new to threading so apologies if I've not understood correctly. I'm trying to create a thread which will run a background Merge Replication sync on a windows mobile device. I need this to run in the background, doing the sync every few minutes but not holding up the main program in the process.

so, here's the code I've created just to test the principle:

Expand|Select|Wrap|Line Numbers
  1. static void ThreadMethod()
  2.     {
  3.         Debug.WriteLine("Thread a " + Thread.CurrentThread.ManagedThreadId + " has control");
  4.         for(int i=0;i<10000;i++){
  5.             Debug.Write("x");
  6.         }
  7.     }
  8.  
  9.     private void runTest(object sender, EventArgs e)
  10.     {
  11.           new Thread(new ThreadStart(ThreadMethod)).Start();
  12.           Debug.WriteLine("Thread b " + Thread.CurrentThread.ManagedThreadId + " has control");
  13.           for (int i = 0; i < 10000; i++)
  14.           {
  15.               Debug.Write("y");
  16.           }
  17.  
  18.  
  19.       }

I was hoping, that as both the code within 'runtest' and 'threadmethod' are running under seperate threads, I'd see a mixture of 'x' and 'y' in the debug console, indicating that they are both running simultaneously.

however I get this:
Expand|Select|Wrap|Line Numbers
  1.  Threadb 1856968798 has control
  2. yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy....yyy
  3. Threada -305810110 has control
  4. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...xxx

This seems to be as though the threads aren't running concurrently.

Am I missing something?

Thanks

Ben
May 5 '10 #1
1 1297
jkmyoung
2,057 Expert 2GB
It could just be there wasn't any time for a switch. I would try with 1000 times the number of characters you have.

Note that it takes a little time to setup the thread (once it declares its intent to run, eg get the requested space for the thread memory etc.. ), so the second thread is bound to run slower. Don't know if your compiler is optimizing at all.
May 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

39
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor...
8
by: Mattias Campe | last post by:
Hello, On http://student.ugent.be/astrid/bewoners.php I got the problem that I want Javascript to let my browser go to http://student.ugent.be/astrid/bewoners.php?beginAcjaar=2002 when I select...
4
by: dot | last post by:
I'm trying to use the following hack to create an expanding/contracting list of links: <html> <head> <script language="Javascript" type="text/javascript"> function ChangeText(obj,...
0
by: Benny Raymond | last post by:
I'm trying to clear out my dataset and start fresh if the user hits "New". However the ID columns of my dataset are not being reset to 1. Can anyone tell me what i'm doing wrong? Here's the code:...
0
by: Web Developer | last post by:
I'm creating an instance of a web service proxy, and setting the PreAuthenticate property to true, but it doesn't seem to have any effect. After creating the proxy instance, I make two web service...
2
by: Sugapablo | last post by:
I have a small test script connecting to a MySQL database. It seems to work, unless I try to use the resource link identifier returned by mysql_connect(); This works and returns all the rows in...
9
by: raiden1985 | last post by:
Please take a look at my code.... Const WM_KEYDOWN As Integer = &H100 Const WM_SYSKEYDOWN As Integer = &H104 Const WM_KEYUP As Integer = &H101 Const WM_SYSKEYUP As Integer =...
7
by: amygdala | last post by:
Hi, I'm trying to let PHP write a 'sitemap.xml' sitemap for Google and other searchengines. It's working, except that the content in the XML file doesn't seem to be UTF8. (Which it should be,...
5
by: fomas87 | last post by:
Hi guys, I'm writing a framework for an sdl gui in c++, but got stuck on the circular dependency, I've read a lot of articles about resolving dependencies and about forward declaration but none of...
1
by: Samuel | last post by:
The MaxLenght property doesn't seem to have any effect
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.