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. multithreading is the problem again.

multithreading is the problem again.

Scheduled Pinned Locked Moved C#
helpquestion
19 Posts 6 Posters 21 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.
  • M Mystic_

    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.

    J Offline
    J Offline
    Judah Gabriel Himango
    wrote on last edited by
    #4

    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

    1 Reply Last reply
    0
    • M Mystic_

      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.

      M Offline
      M Offline
      Mystic_
      wrote on last edited by
      #5

      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

      1 Reply Last reply
      0
      • M Mystic_

        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.

        M Offline
        M Offline
        Mystic_
        wrote on last edited by
        #6

        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.

        E A 2 Replies Last reply
        0
        • M Mystic_

          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.

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #7

          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

          M 1 Reply Last reply
          0
          • E Ennis Ray Lynch Jr

            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

            M Offline
            M Offline
            Mystic_
            wrote on last edited by
            #8

            sorry. that was just a typing mistake. in actual, in source code, it is with Start() method. every thing is getting executed,including threads, but problem is the same. of GUI getting frozen

            1 Reply Last reply
            0
            • M Mystic_

              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.

              A Offline
              A Offline
              Alexander Wiseman
              wrote on last edited by
              #9

              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 on Thread.Start or on some subsequent function. Sincerely, Alexander Wiseman

              M 1 Reply Last reply
              0
              • A 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 on Thread.Start or on some subsequent function. Sincerely, Alexander Wiseman

                M Offline
                M Offline
                Mystic_
                wrote on last edited by
                #10

                i will try that one out. thanx

                A 1 Reply Last reply
                0
                • M Mystic_

                  i will try that one out. thanx

                  A Offline
                  A Offline
                  Alexander Wiseman
                  wrote on last edited by
                  #11

                  If you want, you can post the trace output on the forum here and I'll see if I can help. Sincerely, Alexander Wiseman

                  M 1 Reply Last reply
                  0
                  • A 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

                    M Offline
                    M Offline
                    Mystic_
                    wrote on last edited by
                    #12

                    my application is GUI based so where does Trace write its messages. how can i find them?

                    A 1 Reply Last reply
                    0
                    • M Mystic_

                      my application is GUI based so where does Trace write its messages. how can i find them?

                      A Offline
                      A Offline
                      Alexander Wiseman
                      wrote on last edited by
                      #13

                      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

                      M 2 Replies Last reply
                      0
                      • A 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

                        M Offline
                        M Offline
                        Mystic_
                        wrote on last edited by
                        #14

                        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).

                        1 Reply Last reply
                        0
                        • A 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

                          M Offline
                          M Offline
                          Mystic_
                          wrote on last edited by
                          #15

                          i read it and both the threads which should start r getting started. but GUI still freezes while these two threads execute.

                          A 1 Reply Last reply
                          0
                          • M Mystic_

                            i read it and both the threads which should start r getting started. but GUI still freezes while these two threads execute.

                            A Offline
                            A Offline
                            Alexander Wiseman
                            wrote on last edited by
                            #16

                            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

                            M 1 Reply Last reply
                            0
                            • A 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 Wiseman

                              M Offline
                              M Offline
                              Mystic_
                              wrote on last edited by
                              #17

                              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

                              A 1 Reply Last reply
                              0
                              • M Mystic_

                                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

                                A Offline
                                A Offline
                                Alexander Wiseman
                                wrote on last edited by
                                #18

                                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

                                M 1 Reply Last reply
                                0
                                • A 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

                                  M Offline
                                  M Offline
                                  Mystic_
                                  wrote on last edited by
                                  #19

                                  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??

                                  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