mfc >> Threads problem

by Deepak » Fri, 28 Nov 2003 17:22:02 GMT

Hello,
I am facing a problem in threads.
The problem is that I have placed some picture controls(20) on dialog. In
each picture control I am displaying a graph ( assume sinusoidal). In my
application all the graphs in the picture control should move at a time when
I click on a button.

When I start all the 20 threads only a few (2 - 3) will start moving but the
rest will remain as it is. And when I stop all the threads, rest of the
graphs which didn't move during the process will align to the position of
the moved graphs position.

Why can't I see the other threads functioning? (graph moving)
Can anyone give a suitable answer to over come this problem.

Thanks

Deepak




mfc >> Threads problem

by Scott McPhillips [MVP] » Fri, 28 Nov 2003 18:43:25 GMT






Study the MTGDI MFC sample.

--
Scott McPhillips [VC++ MVP]




Similar Threads

1. Threading & Events Causing Cross Thread Problems - CSharp/C#

2. Odd Thread Problem

Well, I think it is odd.

I have written an application that fires off requests at a COM
component written in VB6.  I am creating multiple threads, one for each
test.

I know that the threads are being created, I know that the calls are
being made to the COM component, I know that the COM component is being
called and is returning a result.

What is going wrong is that if I create 1 thread then the mEvent.Set
command in processThread does not ever get reached and the result is
that WaitAll never finishes.

If I create 6 threads, all of them fire mEvent.Set except for the first
thread.

If I create 10, all complete except the first one.

I have been looking at this for a few hours and I cannot see what is
going wrong.  I have got MTAThread set and I have no idea why this
happening, I have found no pointers searching.

If anyone can explain what I am doing wrong then I would really
appreciate it, I assume it is something daft that I have done.  I
suspect that the first thread is sitting there waiting to do something
but nothing is happening and no exceptions are being raised.

Thanks in advance,
Neil

Part of the code follows:

public PCTestScript RunTests()
{
	Thread[] threadArray = new Thread[m_Threads];
	ManualResetEvent[] manualEvents = new ManualResetEvent[m_Threads];
	WaitHandle[] waitHandle = new WaitHandle[m_Threads];

    for(int i = 0; i < m_Threads; i++)
	{
		manualEvents[i] = new ManualResetEvent(false);
		//waitHandle[i] = (WaitHandle) manualEvents[i];

		PCThread pcThread = new PCThread(manualEvents[i]);
		pcThread.TestScriptRow=m_pcts.PCTestScriptList[i];
		threadArray[i] = new Thread(new ThreadStart(pcThread.processThread));
 //Code below...
		threadArray[i].Name=i.ToString();
		threadArray[i].Start();
	}

	// wait for the work items to signal before exiting.
	ManualResetEvent.WaitAll(manualEvents);
	Console.WriteLine("Finished - Yahoo");

	return m_pcts;
}


public void processThread()
{
	try
	{
		PCInterface pcInterface = new PCInterface();
                //Call to Com Component....

		//This does not get called the FIRST time, why?
		mEvent.Set();
	}
	catch (Exception ex)
	{
		Console.Out.WriteLine("It errored");
	}
}

3. .NET C# ThreadStart (System.Threading) problem - .Net Framework

4. Threading problem

I have written a game that allows the user to upload high scores to the Web.
I now want this upload to occur on a separate thread so that the window
remains responsive.

My attempt looks like this:

m_worker = new Thread(new ThreadStart(UploadScores));
m_worker.Start();
// ...
private void UploadScores()
{
    try { /* ... do the upload ... */ }
    catch (ThreadAbortException ex) { /* user cancelled */ }
    catch (Exception ex) { /* set an error property for the caller to read
*/ }
}
// ...
private void btnCancel_Click(object sender, System.EventArgs e)
{
    if (m_worker != null)
    {
        m_worker.Abort();
        m_worker.Join(); // wait for the thread to abort
    }
}

This seems to work. However, if I cancel and restart the upload a few
times - usually three or four - any subsequent upload attempts fail, timing
out after about a minute.

Is there something wrong with the code above? Am I not disposing of the
thread properly in btnCancel_Click? Is it possible that I am running out of
HttpWebRequest / HttpWebResponse objects because the thread aborts during
the upload?

Any help would be welcome. Debugging threads is a pain.

P.

-- 
www.CL4.org


5. asp.net1.1 threading problem - CSharp/C#

6. Threads problems

7. Threading problem - Urgent Help - CSharp/C#

8. Odd Thread Problem

Well, I think it is odd.


I have written an application that fires off requests at a COM
component written in VB6.  I am creating multiple threads, one for each

test.

I know that the threads are being created, I know that the calls are
being made to the COM component, I know that the COM component is being

called and is returning a result.

What is going wrong is that if I create 1 thread then the mEvent.Set
command in processThread does not ever get reached and the result is
that WaitAll never finishes.

If I create 6 threads, all of them fire mEvent.Set except for the first

thread.

If I create 10, all complete except the first one.

I have been looking at this for a few hours and I cannot see what is
going wrong.  I have got MTAThread set and I have no idea why this
happening, I have found no pointers searching.

If anyone can explain what I am doing wrong then I would really
appreciate it, I assume it is something daft that I have done.  I
suspect that the first thread is sitting there waiting to do something
but nothing is happening and no exceptions are being raised.

Thanks in advance,
Neil

Part of the code follows:

public PCTestScript RunTests()
{
        Thread[] threadArray = new Thread[m_Threads];
        ManualResetEvent[] manualEvents = new
ManualResetEvent[m_Threads];
        WaitHandle[] waitHandle = new WaitHandle[m_Threads];

    for(int i = 0; i < m_Threads; i++)
        {
                manualEvents[i] = new ManualResetEvent(false);
                //waitHandle[i] = (WaitHandle) manualEvents[i];

                PCThread pcThread = new PCThread(manualEvents[i]);
                pcThread.TestScriptRow=m_pcts.CTestScriptList[i];
                threadArray[i] = new Thread(new
ThreadStart(pcThread.processThead));
 //Code below...
                threadArray[i].Name=i.ToString);
                threadArray[i].Start();
        }

        // wait for the work items to signal before exiting.
        ManualResetEvent.WaitAll(manuaEvents);
        Console.WriteLine("Finished - Yahoo");

        return m_pcts;
}


public void processThread()
{
        try
        {
                PCInterface pcInterface = new PCInterface();
                //Call to Com Component....

                //This does not get called the FIRST time, why?
                mEvent.Set();
        }
        catch (Exception ex)
        {
                Console.Out.WriteLine("It errored"); 
        } 
}