troubleshooting Question

Multihreading C# Diploma Project Help

Avatar of IncognitoMan
IncognitoManFlag for Bulgaria asked on
Programming.NET ProgrammingC#
9 Comments1 Solution359 ViewsLast Modified:
Hello guys. I really need help. After less than a week I have to make a domanstration on my diploma project. But it has got a serious bug!
The project contains two threads that handle the voice and the face of a virtual agent.
So the problem is, that there are two threads. The first one, controls the voice. It works OK. But sometimes, one of every five speeches, the second thread, that handles the images, does not start. The second thread changes two pictures. The first one is the agent with closed mouth and the second with closed.
So first I create the threads:
Thread th1;
Thread th2;
After that i assign them a funcion and call them.
th1 = new Thread(ThreadFunc1);
th2 = new Thread(ThreadFunc2);
ThreadFunc1/2 are the functions of the threads.
As I said before, the first thread works fine. But sometimes the socunt funcion doesnt work or... I don't know what happens. Here is its code

public void ThreadFunc2()
{
this.BeginInvoke(new MethodInvoker(delegate()
                {
   //do some calculations
 
   //begin changing the images of the virtual agent.
for (int i = 1; i <= vreme + 1; i++)
                    {
                        pictureNormal.Image = (Image)Properties.Resources.ResourceManager.GetObject("avatar normal");
                        this.Refresh();
                        Thread.Sleep(300);
                        pictureNormal.Image = (Image)Properties.Resources.ResourceManager.GetObject("avatar talk");
                        this.Refresh();
                        Thread.Sleep(300);
                    }
                    pictureNormal.Image = (Image)Properties.Resources.ResourceManager.GetObject("avatar normal");
 }));

So this part changes the picture and makes the thread sleep, after the time is up, lit makes the puts the image of the agent with closed mouth, so it wont be with opened.

But as I said before sometimes it doesnt work. The agent talks but his mouth stays still.
Maybe then I make Thread.Sleep(300); it sleeps the wrong thread and the hole operation just executes rapidly. I don't know I'm out of ideas. Help me pls it's URGENT!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros