Custom event handling

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

In a event, I need to wait until three Flags are set by windows, and then
execute my code. For example I need to wait until InSendMessage() is set to
false and then execute my code in a specific event.

How do I accomplish this? I know threading is a option, but I have very
little experience in writing threads

Can somebody help me out..

VJ
 
Hi VJ,

I think that you can do a endless loop with a sleep in it.
(All is typed here watch typos)
\\\
do while Isready
if mystatus1 = true andalso mystatus2 = true andalso mystatus3 =
true then
Isready = true
else
threading.thread.sleep("100")
application.doevents
loop
///
I would probably use a timer for this.
A normal forms.timer should do this job and set that routine in the
tick.event

I hope this helps?

Cor
 
Cor,

If I putt a loop like this, will it not cause a single thread execution? I
mean this processor will get in this loop and not process the other event
which has to set the flag. Wouldn't this cause a infinite loop?.. The reason
I am saying this, I actually tried something like this.. and ended up in a
infinite loop...

I will actually explain my problem in more detail..

I have this Ink Picture control resize event, where I have to scale this ink
displayed, when the window or the control size changes. The resize code
works perfectly, expect when one of theses flags (InSendMessage, inkPicture
is Nothing, InkPicture.IsCollecting) is true. What happens here is my if one
of my IF condition fails..(see code below).. I don't get the original height
and width set at that time plus the scaling does not happen. This screws up
the scaling factor.. and hence the current scaling and any scaling happening
after that is messed up.. Also, the resize never gets called after this.
This the reason I am asking is there a way out to wait till these flags are
set by windows and then do my resize.

If Not InSendMessage() Then 'InSendMessage is a WindowsAPI used to
detect if the COM Interop process is busy, this check is need during
rotation of the screen.
If orgWidth > 0 And orgHeight > 0 Then
If Single.Parse(inkPicture1.Width.ToString) > 0 And
Single.Parse(inkPicture1.Height.ToString) > 0 Then
If Not inkPicture1 Is Nothing Then 'The Picture control
actually gets disposed when screen is in Rotation, so check for it
If Not inkPicture1.CollectingInk Then '3/5 times the
inkPicture is busy collecting Ink, so resize can't happen here..Mostly
during screen rotate.

inkPicture1.Renderer.Scale(Single.Parse(inkPicture1.Width.ToString) /
orgWidth, Single.Parse(inkPicture1.Height.ToString) / orgHeight, False)
orgHeight =
Single.Parse(inkPicture1.Height.ToString)
orgWidth = Single.Parse(inkPicture1.Width.ToString)
End If
End If
End If
End If
End If

I am going to copy this to the Tablet PC newsgroup. I am really surprised
nobody has every faced this ink scaling/display resize problem, or maybe I
am doing something worng..

Thanks for the help...

VJ
 
HI VJ,

That loop should not be endless when those values can become true.
But maybe this is better, also typed here just as pseudo.

I hope this helps,

Cor

\\\
drag a forms timer from the toolbox to your form or set it with events
timer1.enabled = true
dim timercontrol as integer = 0
private sub ,,,,,,,, handles timer.tick
if timercontrol<100 then
if mystatus1 = true andalso mystatus2 = true andalso mystatus3 = true
then
do what you have to do
timer1.enabled=false
else
control +=1
end if
else
'it is a little bit long now, take some action
end if
////
 
I still have a problem, The Application.Doevents() or using a timer, does
not cause my application to wait and go process the other thread so the flag
can be set, so hence there is a infinite loop... I am really confused...

VJ
 
Cor Thanks for your help.. Got this one.. This code has to be written in the
control's paint event, in which case the flags area already set by windows,
so I don't do the check. I just write my code and it works.. The code passed
my unit testing and is now with testers for regression testing , fingers
Xed....:-)

VJ
 
Back
Top