Click here to Skip to main content
15,899,475 members
Home / Discussions / C#
   

C#

 
AnswerRe: Open Directory Dialog Pin
mikker_12327-Feb-06 10:24
mikker_12327-Feb-06 10:24 
GeneralRe: Open Directory Dialog Pin
tray_gator27-Feb-06 11:09
tray_gator27-Feb-06 11:09 
QuestionKeeping track of users within a server Pin
paranoiduk27-Feb-06 10:08
paranoiduk27-Feb-06 10:08 
QuestionTTH code in practical use... Pin
Smilik27-Feb-06 9:17
Smilik27-Feb-06 9:17 
Questiondirectx: how to turn of mesh smoothing? Pin
kopi_b27-Feb-06 8:43
kopi_b27-Feb-06 8:43 
QuestionRegarding DomainUpDown control Pin
Vijaykumar Rajaram27-Feb-06 8:40
Vijaykumar Rajaram27-Feb-06 8:40 
AnswerRe: Regarding DomainUpDown control Pin
Vijaykumar Rajaram27-Feb-06 9:09
Vijaykumar Rajaram27-Feb-06 9:09 
QuestionDebugging multithreaded C# windows app Pin
reduzent27-Feb-06 8:20
reduzent27-Feb-06 8:20 
Hi,

after reading a lot of forum threads i am wondering that no one else has the problem I am having. Here it is: I am starting programming with C# and .NET with VisualC# Express. I tried to implement multithreading in my test app. The app runs but when I set breakpoint in the code that is executed by a worker thread then:

- the debugger stops at the breakpoint
- the GUI freezes for a couple of seconds and then
- I am not able to get the interrupted thread running again

I have written a small test application to demonstrate this behaviour. It opens a form with a button and 4 textboxes. When the button is pressed 4 threads will be started, that increment a local variable and display the value of the variable in the textbox (each thread has its own textbox). When the threads are running I can see that the numbers in the textboxes are increasing. When I set a breakpoint in the thread code, the execution stops. I must wait a few seconds before the GUI (VC) responds and if I then let the app run again (after removing the breakpoint) I can see that the thread that was interrupted does not work anymore (textbox value does not change).

What could cause this behaviour. I think that I am having a general problem but I dont know where to start to search.

The source of the test application:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace MTWindowsTestApp
{
    public partial class Form1 : Form
    {
        int m_nThreadCount;
        bool m_bExit;
        
        public Form1()
        {
            InitializeComponent();
            m_nThreadCount = 0;
            m_bExit = false;
        }

        private void button1_Click( object sender, EventArgs e )
        {
            Thread t;
            int i;

            // 4 Threads starten
            for( i = 0; i < 4; ++i )
            {
                t = new Thread( new ParameterizedThreadStart( MyThread ) );
                t.Priority = ThreadPriority.BelowNormal;
                t.Start( new ThreadData( m_nThreadCount++ ) );
                //Thread.Sleep( 500 );
            }
        }

        public delegate void SetTextDelegate( string strText,
            ThreadData td );
        public void SetText( string strText, ThreadData td )
        {
            switch( td.m_nNr )
            {
                case 0:
                {
                    textBox1.Text = strText;
                    break;
                }
                case 1:
                {
                    textBox2.Text = strText;
                    break;
                }
                case 2:
                {
                    textBox3.Text = strText;
                    break;
                }
                case 3:
                {
                    textBox4.Text = strText;
                    break;
                }
            }
        }
        
        public void MyThread( object Data )
        {
            int nCount;
            int nData = ( (ThreadData)Data ).m_nNr;
            string strTemp;

            nCount = 0;
            strTemp = nData.ToString();
            //while( !m_bExit )
            while( true )
            {
                strTemp = "Thread " + nData.ToString() + ": " +
                    nCount.ToString();
                BeginInvoke( new SetTextDelegate( SetText ),
                    new object[] { strTemp, Data } );
                nCount++;
                Thread.Sleep( 10 );
            }
        }

        private void Form1_FormClosing( object sender, FormClosingEventArgs e )
        {
            m_bExit = true;
        }

    }

    public class ThreadData
    {
        public int m_nNr;
        public ThreadData( int nNr )
        {
            m_nNr = nNr;
        }
    }
}



Thanks in advance.
AnswerRe: Debugging multithreaded C# windows app Pin
mikker_12327-Feb-06 10:30
mikker_12327-Feb-06 10:30 
GeneralRe: Debugging multithreaded C# windows app Pin
reduzent27-Feb-06 19:44
reduzent27-Feb-06 19:44 
GeneralRe: Debugging multithreaded C# windows app Pin
reduzent27-Feb-06 22:26
reduzent27-Feb-06 22:26 
GeneralRe: Debugging multithreaded C# windows app Pin
reduzent28-Feb-06 4:51
reduzent28-Feb-06 4:51 
QuestionPrimary key Ascending Pin
ytubis27-Feb-06 8:12
ytubis27-Feb-06 8:12 
AnswerRe: Primary key Ascending Pin
Steve Maier27-Feb-06 8:41
professionalSteve Maier27-Feb-06 8:41 
QuestionHow to delete a picture??? Pin
CrazyDragon638427-Feb-06 7:53
CrazyDragon638427-Feb-06 7:53 
AnswerRe: How to delete a picture??? Pin
mav.northwind27-Feb-06 8:04
mav.northwind27-Feb-06 8:04 
GeneralRe: How to delete a picture??? Pin
CrazyDragon638427-Feb-06 15:12
CrazyDragon638427-Feb-06 15:12 
GeneralRe: How to delete a picture??? Pin
mav.northwind27-Feb-06 20:08
mav.northwind27-Feb-06 20:08 
GeneralRe: How to delete a picture??? Pin
CrazyDragon638428-Feb-06 15:25
CrazyDragon638428-Feb-06 15:25 
GeneralRe: How to delete a picture??? Pin
mav.northwind28-Feb-06 21:28
mav.northwind28-Feb-06 21:28 
GeneralRe: How to delete a picture??? Pin
CrazyDragon63841-Mar-06 7:22
CrazyDragon63841-Mar-06 7:22 
GeneralRe: How to delete a picture??? Pin
mav.northwind1-Mar-06 7:48
mav.northwind1-Mar-06 7:48 
GeneralRe: How to delete a picture??? Pin
CrazyDragon63842-Mar-06 3:21
CrazyDragon63842-Mar-06 3:21 
QuestionForcing MSIL code to Native code? Pin
pankazmittal27-Feb-06 7:33
pankazmittal27-Feb-06 7:33 
AnswerRe: Forcing MSIL code to Native code? Pin
mav.northwind27-Feb-06 8:02
mav.northwind27-Feb-06 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.