Problem with multi threading
-
I have placed a gif animation Control(Gif89) in my Dialog based application and in a thread i tried to move the gif's control (with a loaded picture) through the bottom of my Dialog using Move Window() function.A delay of 1ms is introduced between successive calls to move window. I use a timer to communicate with an external device connected to serial port. It takes almost 3 seconds to finish communication. During this time my thread seems to be strucked and gif control is not moved over my main dialog.How can i avoid this?. the code in the thread for moving control is given below int offsetx=0;//65 int offsety=444; int step=0; while(killthread) { m_santa.MoveWindow(offsetx+step,offsety,159,76); Sleep(1); step=step+1; if(offsetx+step>483)//314) step=0; With regards Shibu "Help yourself through helping others"
-
I have placed a gif animation Control(Gif89) in my Dialog based application and in a thread i tried to move the gif's control (with a loaded picture) through the bottom of my Dialog using Move Window() function.A delay of 1ms is introduced between successive calls to move window. I use a timer to communicate with an external device connected to serial port. It takes almost 3 seconds to finish communication. During this time my thread seems to be strucked and gif control is not moved over my main dialog.How can i avoid this?. the code in the thread for moving control is given below int offsetx=0;//65 int offsety=444; int step=0; while(killthread) { m_santa.MoveWindow(offsetx+step,offsety,159,76); Sleep(1); step=step+1; if(offsetx+step>483)//314) step=0; With regards Shibu "Help yourself through helping others"
Firstly,
Sleep()
does not have anywhere near 1 ms granularity.Sleep(1)
will sleep for about 50 ms probably. But what's causing the apparent hang is that (I'm guessing here, CMIIW) the thread did not createm_santa
, the main thread did. Since messages for a window must be handled by the thread that created the window,MoveWindow()
ends up doing aSendMessage()
to the main thread, to have it move the window.SendMessage()
does not return until the message is processed. But since the main thread is busy doing your serial port comm, it is not running its message loop. Thus you have a deadlock, the main thread is busy, and the 2nd thread can't continue until the main thread is done being busy. --Mike-- If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm -
Firstly,
Sleep()
does not have anywhere near 1 ms granularity.Sleep(1)
will sleep for about 50 ms probably. But what's causing the apparent hang is that (I'm guessing here, CMIIW) the thread did not createm_santa
, the main thread did. Since messages for a window must be handled by the thread that created the window,MoveWindow()
ends up doing aSendMessage()
to the main thread, to have it move the window.SendMessage()
does not return until the message is processed. But since the main thread is busy doing your serial port comm, it is not running its message loop. Thus you have a deadlock, the main thread is busy, and the 2nd thread can't continue until the main thread is done being busy. --Mike-- If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape. 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_HelmWell...depending on the operating system 'Sleep()' will sleep between 10 (Single CPU Windows NT) milliseconds and 50 milliseconds (Windows 98). I do not know of the top of my head whether Windows 2000 or XP have better resolution... Ciao, Andreas "Software is like sex, it's better when it's free." - Linus Torvalds