multithreading is the problem again.
-
i have a program in which i have a switch statement and subsequent case statements in which i start some threads(each per case).i have not implemented any Gui event handlers as of yet but my application freezes for as long as those threads reach to completion. what may be the probelm? i can send the sample code if someone may wish to see it.
Mystic_ wrote:
i can send the sample code if someone may wish to see it.
How about just the switch snippet statement and the line where the app freezes? That would be the most helpful and is your best bet to get an answer to your question.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
i have a program in which i have a switch statement and subsequent case statements in which i start some threads(each per case).i have not implemented any Gui event handlers as of yet but my application freezes for as long as those threads reach to completion. what may be the probelm? i can send the sample code if someone may wish to see it.
to give u idea of what iam saying. this is just a picture of what iam trying to imply i have a class public class Form1 : System.Windows.Forms.Form { public struct Data { public int data; public Element_tg element; } public class Element_tg { public string elementstr; public int count; public bool last; public int set_ele; public Element_tg child; public Element_tg parent; } pubic class ThreadProp { public static Data info1,info2; public static string file1,file2; public static string origin; public static string filename; public static bool nav; public static NameValueCollection nvcol; public static string url; public static Uri uri; public static string result; public void Ext_Text()// uses string file1, Data info1, bool nav { //uses a com component and rest all is simple programming / /its a lengthy code } public void Test_Download()// uses string file2, Data info2,string origin,string filename { //call another function which interacts with internet for downloads } public void WebInteract()//uses string url, (this ones not necessary) string type,NameValueCollection nvcol { //this one also interacts with internet } } [STAThread] static void Main() { Application.Run(new Form1()); } private void bt_load_Click(object sender, System.EventArgs e) { ThreadProp tr=new ThreadProp(); switch() { case 1: Thread thrr=new Thread(new ThreadStart(tr.Ext_Text)); thrr.Start(); break; case 2: Thread thrr=new Thread(new ThreadStart(tr.Test_Download)); thrr.Start(); break; case 3: Thread thrr=new Thread(new ThreadStart(tr. WebInteract)); thrr.Start(); break; } } } -- modified at 19:02 Monday 17th July, 2006
-
i have a program in which i have a switch statement and subsequent case statements in which i start some threads(each per case).i have not implemented any Gui event handlers as of yet but my application freezes for as long as those threads reach to completion. what may be the probelm? i can send the sample code if someone may wish to see it.
now let me state the problem again. problem is this that i used multithreading to remove this short comming from my program, that it halts when in execution. even with multiple threads its halt when executing. that is it dont respond to gui interaction. its GUI freezes. i used ThreadPool too but that wont solve my problem either.
-
now let me state the problem again. problem is this that i used multithreading to remove this short comming from my program, that it halts when in execution. even with multiple threads its halt when executing. that is it dont respond to gui interaction. its GUI freezes. i used ThreadPool too but that wont solve my problem either.
Thread thread = new Thread(new ThreadStart()) thread.Start() A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
-
Thread thread = new Thread(new ThreadStart()) thread.Start() A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
-
now let me state the problem again. problem is this that i used multithreading to remove this short comming from my program, that it halts when in execution. even with multiple threads its halt when executing. that is it dont respond to gui interaction. its GUI freezes. i used ThreadPool too but that wont solve my problem either.
I would put some tracing in a few of those functions to try and narrow down the bottle-neck. For instance, put a
System.Diagnostics.Trace.WriteLine
call before and after you spawn the new thread. Also put in a trace inside each thread function, at the beginning and at the end. Run the program in debug mode and check the output. It would be particularly helpful to know if your main thread is getting stuck onThread.Start
or on some subsequent function. Sincerely, Alexander Wiseman -
I would put some tracing in a few of those functions to try and narrow down the bottle-neck. For instance, put a
System.Diagnostics.Trace.WriteLine
call before and after you spawn the new thread. Also put in a trace inside each thread function, at the beginning and at the end. Run the program in debug mode and check the output. It would be particularly helpful to know if your main thread is getting stuck onThread.Start
or on some subsequent function. Sincerely, Alexander Wiseman -
If you want, you can post the trace output on the forum here and I'll see if I can help. Sincerely, Alexander Wiseman
-
If you want, you can post the trace output on the forum here and I'll see if I can help. Sincerely, Alexander Wiseman
-
There are two ways to see the output: First, the quick and easy way: 1) If you're using Visual Studio, then run the program in debug mode by pressing F5. When the program exits, you can see all of the trace output in the "Output" window - the same window in which you see the results of the last Build command. In VS 2003 (and I think it is probably in 2002 as well), there is a drop-down box which allows you to select what kind of output you wish to view. After running the program in debug mode, my VS window shows two options "Build" and "Debug". If you set it on "Debug", you should see the trace output. Second, the way which takes a little bit longer, but results are more permanent: 2) Setup a
TextWriterTraceListener
which will automatically write trace output to a file. Here's how: first, you'll need to make sure you reference the System.Diagnostics namespace in your main form file:using System.Diagnostics;
Second, put a variable in your main form code:
private TextWriterTraceListener myListener;
Now, put the following code into your application's main form constructor, or Load event handler:
myListener = new TextWriterTraceListener("logFile.txt");
Trace.Listeners.Add(myListener);And you're done! Run the program and then look at the file "logFile.txt" for the output. Hope that helps! Let me know what you find. Sincerely, Alexander Wiseman
-
There are two ways to see the output: First, the quick and easy way: 1) If you're using Visual Studio, then run the program in debug mode by pressing F5. When the program exits, you can see all of the trace output in the "Output" window - the same window in which you see the results of the last Build command. In VS 2003 (and I think it is probably in 2002 as well), there is a drop-down box which allows you to select what kind of output you wish to view. After running the program in debug mode, my VS window shows two options "Build" and "Debug". If you set it on "Debug", you should see the trace output. Second, the way which takes a little bit longer, but results are more permanent: 2) Setup a
TextWriterTraceListener
which will automatically write trace output to a file. Here's how: first, you'll need to make sure you reference the System.Diagnostics namespace in your main form file:using System.Diagnostics;
Second, put a variable in your main form code:
private TextWriterTraceListener myListener;
Now, put the following code into your application's main form constructor, or Load event handler:
myListener = new TextWriterTraceListener("logFile.txt");
Trace.Listeners.Add(myListener);And you're done! Run the program and then look at the file "logFile.txt" for the output. Hope that helps! Let me know what you find. Sincerely, Alexander Wiseman
its in the start of web interaction its in the end of Web interaction its in the start of text extract its in the end of text extract 'Testing.exe': Loaded 'c:\windows\assembly\gac\microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\microsoft.mshtml.dll', No symbols loaded. The thread '' (0xc9c) has exited with code 0 (0x0). 'Testing.exe': Loaded 'c:\windows\assembly\gac\custommarshalers\1.0.5000.0__b03f5f7f11d50a3a\custommarshalers.dll', No symbols loaded. The thread '' (0xf78) has exited with code 0 (0x0).
-
There are two ways to see the output: First, the quick and easy way: 1) If you're using Visual Studio, then run the program in debug mode by pressing F5. When the program exits, you can see all of the trace output in the "Output" window - the same window in which you see the results of the last Build command. In VS 2003 (and I think it is probably in 2002 as well), there is a drop-down box which allows you to select what kind of output you wish to view. After running the program in debug mode, my VS window shows two options "Build" and "Debug". If you set it on "Debug", you should see the trace output. Second, the way which takes a little bit longer, but results are more permanent: 2) Setup a
TextWriterTraceListener
which will automatically write trace output to a file. Here's how: first, you'll need to make sure you reference the System.Diagnostics namespace in your main form file:using System.Diagnostics;
Second, put a variable in your main form code:
private TextWriterTraceListener myListener;
Now, put the following code into your application's main form constructor, or Load event handler:
myListener = new TextWriterTraceListener("logFile.txt");
Trace.Listeners.Add(myListener);And you're done! Run the program and then look at the file "logFile.txt" for the output. Hope that helps! Let me know what you find. Sincerely, Alexander Wiseman
-
i read it and both the threads which should start r getting started. but GUI still freezes while these two threads execute.
Did you put a trace command after the
new Thread(new ThreadStart(...))
line in the main code? If not, try that first. If so, did it get output? That is an important point because it will determine whether your main application is getting stuck on the creation of the thread, or on a subsequent call. Sincerely, Alexander Wiseman -
Did you put a trace command after the
new Thread(new ThreadStart(...))
line in the main code? If not, try that first. If so, did it get output? That is an important point because it will determine whether your main application is getting stuck on the creation of the thread, or on a subsequent call. Sincerely, Alexander Wisemanits in the start of web interaction its in the end of Web interaction its in the start of text extract its in the end of text extract 'Testing.exe': Loaded 'c:\windows\assembly\gac\microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\microsoft.mshtml.dll', No symbols loaded. The thread '' (0xc9c) has exited with code 0 (0x0). 'Testing.exe': Loaded 'c:\windows\assembly\gac\custommarshalers\1.0.5000.0__b03f5f7f11d50a3a\custommarshalers.dll', No symbols loaded. The thread '' (0xf78) has exited with code 0 (0x0). The four starting lines r produced by Trace. "its in the start of web interaction" was written before one .Start() method and the "its in the end of Web interaction" is used after .Start() method and same applies to the 2 lines below that. they r giving output
-
its in the start of web interaction its in the end of Web interaction its in the start of text extract its in the end of text extract 'Testing.exe': Loaded 'c:\windows\assembly\gac\microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\microsoft.mshtml.dll', No symbols loaded. The thread '' (0xc9c) has exited with code 0 (0x0). 'Testing.exe': Loaded 'c:\windows\assembly\gac\custommarshalers\1.0.5000.0__b03f5f7f11d50a3a\custommarshalers.dll', No symbols loaded. The thread '' (0xf78) has exited with code 0 (0x0). The four starting lines r produced by Trace. "its in the start of web interaction" was written before one .Start() method and the "its in the end of Web interaction" is used after .Start() method and same applies to the 2 lines below that. they r giving output
It seems to me that you are actually getting the trace output after you call
Thread.Start
and before the generated thread finishes. This suggests that your thread starting code isn't a problem at all, but perhaps something that your main code is doing after it starts the threads is causing the GUI to lock up. I would look closely at the code which gets executed on your main thread after you start the worker threads (I don't think you posted that code on the boards).Sincerely, Alexander Wiseman
-
It seems to me that you are actually getting the trace output after you call
Thread.Start
and before the generated thread finishes. This suggests that your thread starting code isn't a problem at all, but perhaps something that your main code is doing after it starts the threads is causing the GUI to lock up. I would look closely at the code which gets executed on your main thread after you start the worker threads (I don't think you posted that code on the boards).Sincerely, Alexander Wiseman
its all the main() had. main function has only this static void Main() { Application.Run(new Form1()); } as i said reall execution, that is bussiness logic, when i click the button. so all the code in private void bt_load_Click(object sender, System.EventArgs e) { } its getting more and more tricky. isnt it??