Hi :
I have created a Class where this contains a timer , each time the timer
control been activate or its interval time has elpased a new window must
appear and deseapear ,, ( com kind of alarm) ,, I created another class
(form) that is instanced when the peiod time from my Class A is executed ..
Why the event Method DO not fires !! ? , Why if I Instance the Class from
another Form it Works , but When I Instance The Class From My Class Don't
Work.

Tank Very Much for your help ...

Re: Paint event don't Work by Jon

Jon
Fri Jan 06 13:06:49 CST 2006

Josue Avila Mendoza <JosueAvilaMendoza@discussions.microsoft.com>
wrote:
> Hi :
> I have created a Class where this contains a timer , each time the timer
> control been activate or its interval time has elpased a new window must
> appear and deseapear ,, ( com kind of alarm) ,, I created another class
> (form) that is instanced when the peiod time from my Class A is executed ..
> Why the event Method DO not fires !! ? , Why if I Instance the Class from
> another Form it Works , but When I Instance The Class From My Class Don't
> Work.
>
> Tank Very Much for your help ...

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Re: Paint event don't Work by Stoitcho

Stoitcho
Fri Jan 06 15:22:52 CST 2006

What kind of timer do you use? If you use something different than
System.Windows.Forms.Timer it is most likely the timer event is executed in
a worker thread that is not UI (doesn't run a message pump) in this case the
new form won't receive WM_PAINT, thus won't redraw.

What you need to do is to marshal code execution using Control.Invoke to the
UI thread that shows the main form.


--

Stoitcho Goutsev (100)

"Josue Avila Mendoza" <JosueAvilaMendoza@discussions.microsoft.com> wrote in
message news:8852DBBE-7E22-40FA-AC20-EA5A545CB75F@microsoft.com...
> Hi :
> I have created a Class where this contains a timer , each time the timer
> control been activate or its interval time has elpased a new window must
> appear and deseapear ,, ( com kind of alarm) ,, I created another class
> (form) that is instanced when the peiod time from my Class A is executed
> ..
> Why the event Method DO not fires !! ? , Why if I Instance the Class from
> another Form it Works , but When I Instance The Class From My Class Don't
> Work.
>
> Tank Very Much for your help ...
>



Re: Paint event don't Work by JosueAvilaMendoza

JosueAvilaMendoza
Fri Jan 06 17:37:02 CST 2006

Hi Stoitcho
Actually Im Using Threading.Timer In order to execute the Sub that shows
de Window in other Thread ..
You said i have to Use control.invoke() ? how can i use it ?



"Stoitcho Goutsev (100) [C# MVP]" wrote:

> What kind of timer do you use? If you use something different than
> System.Windows.Forms.Timer it is most likely the timer event is executed in
> a worker thread that is not UI (doesn't run a message pump) in this case the
> new form won't receive WM_PAINT, thus won't redraw.
>
> What you need to do is to marshal code execution using Control.Invoke to the
> UI thread that shows the main form.
>
>
> --
>
> Stoitcho Goutsev (100)
>
> "Josue Avila Mendoza" <JosueAvilaMendoza@discussions.microsoft.com> wrote in
> message news:8852DBBE-7E22-40FA-AC20-EA5A545CB75F@microsoft.com...
> > Hi :
> > I have created a Class where this contains a timer , each time the timer
> > control been activate or its interval time has elpased a new window must
> > appear and deseapear ,, ( com kind of alarm) ,, I created another class
> > (form) that is instanced when the peiod time from my Class A is executed
> > ..
> > Why the event Method DO not fires !! ? , Why if I Instance the Class from
> > another Form it Works , but When I Instance The Class From My Class Don't
> > Work.
> >
> > Tank Very Much for your help ...
> >
>
>
>

Re: Paint event don't Work by Jon

Jon
Fri Jan 06 17:54:18 CST 2006

Josue Avila Mendoza <JosueAvilaMendoza@discussions.microsoft.com>
wrote:
> Hi Stoitcho
> Actually Im Using Threading.Timer In order to execute the Sub that shows
> de Window in other Thread ..
> You said i have to Use control.invoke() ? how can i use it ?

See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Re: Paint event don't Work by Stoitcho

Stoitcho
Mon Jan 09 08:11:33 CST 2006

Josue,

Did Jon's article help you?


--

Stoitcho Goutsev (100)

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1e29138958d0c65198cc87@msnews.microsoft.com...
> Josue Avila Mendoza <JosueAvilaMendoza@discussions.microsoft.com>
> wrote:
>> Hi Stoitcho
>> Actually Im Using Threading.Timer In order to execute the Sub that
>> shows
>> de Window in other Thread ..
>> You said i have to Use control.invoke() ? how can i use it ?
>
> See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too



Re: Paint event don't Work by JosueAvilaMendoza

JosueAvilaMendoza
Mon Jan 09 09:10:03 CST 2006

Hi
It is not posible for me to acces into the link ; i Think is Firewall issues
..
But Look this is a part from my class code ..

Public Class AlertsEngine
Private LCCollectionAlerts As Alerts
Private LCDCAlertEngine As DCAlertEngine = New DCAlertEngine
Private InstanceSearcher As New TimerCallback(AddressOf Me.Search)
Private LCInterval As Integer = 8000
Private StateTimer As Timer
Public Event showAlert(ByVal strAlertMessage As String)


Sub New(ByVal ObjAlertClct As Alerts)
Me.LCCollectionAlerts = ObjAlertClct
End Sub

Public Function Start()
Me.StateTimer = New Timer(InstanceSearcher, Nothing, LCInterval, 250)
StateTimer.Change(250, LCInterval)
End Function

Public Function [Stop]()
If Not Me.StateTimer Is Nothing Then
StateTimer.Change(0, 0)
End If
End Function


Private Sub Search(ByVal Stateinfo As Object)

Dim TmpAlert As Alert
Dim DrRowAlerToAcv As DataRow

For Each TmpAlert In Me.LCCollectionAlerts
Dim TmpAlertSubRows As DataTable = TmpAlert.GetRecordsInAlertsOn()

For Each DrRowAlerToAcv In TmpAlertSubRows.Rows
Dim strAlertMsg As String =
TmpAlert.AlertMessage.ToString(DrRowAlerToAcv)

Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin
Alert...", 3000)
NewAlrtfrm.ShowInTaskbar = False
NewAlrtfrm.Show()




RaiseEvent showAlert(strAlertMsg)
Call FlagRecord(TmpAlert, DrRowAlerToAcv)
Next
Next

End Sub

End Class



Into the Search Sub you may see that im instancing the form AlertSpace :

Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin Alert...", 3000)

When this line is executed: The form is showed however, the paint events
(form.paint) and (panel1.paint) ; (im using a paint object into to) are not
executed ..

=( Thank you very much for your help ; and any advice you can give..



Re: Paint event don't Work by Jon

Jon
Mon Jan 09 12:38:55 CST 2006

Josue Avila Mendoza <JosueAvilaMendoza@discussions.microsoft.com>
wrote:
> It is not posible for me to acces into the link ; i Think is Firewall issues

Try http://www.yoda.arachsys.com/csharp/threads/winforms.shtml

It's the same link, just not going through pobox.

Instead of posting part of your code, I suggest you post a short but
complete example. See http://www.yoda.arachsys.com/csharp/complete.html
for details of what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Re: Paint event don't Work by Stoitcho

Stoitcho
Mon Jan 09 13:47:15 CST 2006

Josue,

You cannot show a form like this. The thread that executes the event is not
an UI thread. You need to either create a UI thread or create the form in
the main UI thread.
Starting a message pump in the thread where timer event is fired is not a
good idea because this thread is borrowed from the thread pool where the
threads are limited number, thus using the main thread is better approach.

To create the form in the main thread you need to have reference to some
control from the main UI (say reference to the form). Basically this work as
follows (I write this in c# because I'm not very comfortable with the VB
syntax.

void CreateAForm(Param1, Param2, ....)
{
if(aControl.InvokeRequired)
{
SomeDelegate someDelegate = new SomeDelegate(CreateAForm)
// aControl is a reference to a control from the main UI
aControl.Invoke(someDelegate, new object[]{param1, param2, ....});
return; //NOTE: This return is very important
}

<All the code for creating, initializing and showing the new form>
}


--
HTH
Stoitcho Goutsev (100)



"Josue Avila Mendoza" <JosueAvilaMendoza@discussions.microsoft.com> wrote in
message news:68229EAF-187C-4264-8E36-210C1849BF0E@microsoft.com...
> Hi
> It is not posible for me to acces into the link ; i Think is Firewall
> issues
> ..
> But Look this is a part from my class code ..
>
> Public Class AlertsEngine
> Private LCCollectionAlerts As Alerts
> Private LCDCAlertEngine As DCAlertEngine = New DCAlertEngine
> Private InstanceSearcher As New TimerCallback(AddressOf Me.Search)
> Private LCInterval As Integer = 8000
> Private StateTimer As Timer
> Public Event showAlert(ByVal strAlertMessage As String)
>
>
> Sub New(ByVal ObjAlertClct As Alerts)
> Me.LCCollectionAlerts = ObjAlertClct
> End Sub
>
> Public Function Start()
> Me.StateTimer = New Timer(InstanceSearcher, Nothing, LCInterval,
> 250)
> StateTimer.Change(250, LCInterval)
> End Function
>
> Public Function [Stop]()
> If Not Me.StateTimer Is Nothing Then
> StateTimer.Change(0, 0)
> End If
> End Function
>
>
> Private Sub Search(ByVal Stateinfo As Object)
>
> Dim TmpAlert As Alert
> Dim DrRowAlerToAcv As DataRow
>
> For Each TmpAlert In Me.LCCollectionAlerts
> Dim TmpAlertSubRows As DataTable =
> TmpAlert.GetRecordsInAlertsOn()
>
> For Each DrRowAlerToAcv In TmpAlertSubRows.Rows
> Dim strAlertMsg As String =
> TmpAlert.AlertMessage.ToString(DrRowAlerToAcv)
>
> Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin
> Alert...", 3000)
> NewAlrtfrm.ShowInTaskbar = False
> NewAlrtfrm.Show()
>
>
>
>
> RaiseEvent showAlert(strAlertMsg)
> Call FlagRecord(TmpAlert, DrRowAlerToAcv)
> Next
> Next
>
> End Sub
>
> End Class
>
>
>
> Into the Search Sub you may see that im instancing the form AlertSpace :
>
> Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin Alert...", 3000)
>
> When this line is executed: The form is showed however, the paint events
> (form.paint) and (panel1.paint) ; (im using a paint object into to) are
> not
> executed ..
>
> =( Thank you very much for your help ; and any advice you can give..
>
>



Re: Paint event don't Work by Stoitcho

Stoitcho
Tue Jan 10 08:39:01 CST 2006

Actually there is a easier solutions than the one I already suggested. I
just forgot to mention them with my last post.

1. Use System.Windows.Forms.Timer if timer accuracy is not an issue for you.

2. Use System.Timers.Timer instead of System.Threading.Timer. Timers.Timer
has a property - SynchronizingObject that you can set with a reference to a
control form the main UI and it will marshal the event for execution in the
UI thread for you.


--
HTH
Stoitcho Goutsev (100)

"Stoitcho Goutsev (100)" <100@100.com> wrote in message
news:evBMqUVFGHA.516@TK2MSFTNGP15.phx.gbl...
> Josue,
>
> You cannot show a form like this. The thread that executes the event is
> not an UI thread. You need to either create a UI thread or create the form
> in the main UI thread.
> Starting a message pump in the thread where timer event is fired is not a
> good idea because this thread is borrowed from the thread pool where the
> threads are limited number, thus using the main thread is better approach.
>
> To create the form in the main thread you need to have reference to some
> control from the main UI (say reference to the form). Basically this work
> as follows (I write this in c# because I'm not very comfortable with the
> VB syntax.
>
> void CreateAForm(Param1, Param2, ....)
> {
> if(aControl.InvokeRequired)
> {
> SomeDelegate someDelegate = new SomeDelegate(CreateAForm)
> // aControl is a reference to a control from the main UI
> aControl.Invoke(someDelegate, new object[]{param1, param2, ....});
> return; //NOTE: This return is very important
> }
>
> <All the code for creating, initializing and showing the new form>
> }
>
>
> --
> HTH
> Stoitcho Goutsev (100)
>
>
>
> "Josue Avila Mendoza" <JosueAvilaMendoza@discussions.microsoft.com> wrote
> in message news:68229EAF-187C-4264-8E36-210C1849BF0E@microsoft.com...
>> Hi
>> It is not posible for me to acces into the link ; i Think is Firewall
>> issues
>> ..
>> But Look this is a part from my class code ..
>>
>> Public Class AlertsEngine
>> Private LCCollectionAlerts As Alerts
>> Private LCDCAlertEngine As DCAlertEngine = New DCAlertEngine
>> Private InstanceSearcher As New TimerCallback(AddressOf Me.Search)
>> Private LCInterval As Integer = 8000
>> Private StateTimer As Timer
>> Public Event showAlert(ByVal strAlertMessage As String)
>>
>>
>> Sub New(ByVal ObjAlertClct As Alerts)
>> Me.LCCollectionAlerts = ObjAlertClct
>> End Sub
>>
>> Public Function Start()
>> Me.StateTimer = New Timer(InstanceSearcher, Nothing, LCInterval,
>> 250)
>> StateTimer.Change(250, LCInterval)
>> End Function
>>
>> Public Function [Stop]()
>> If Not Me.StateTimer Is Nothing Then
>> StateTimer.Change(0, 0)
>> End If
>> End Function
>>
>>
>> Private Sub Search(ByVal Stateinfo As Object)
>>
>> Dim TmpAlert As Alert
>> Dim DrRowAlerToAcv As DataRow
>>
>> For Each TmpAlert In Me.LCCollectionAlerts
>> Dim TmpAlertSubRows As DataTable =
>> TmpAlert.GetRecordsInAlertsOn()
>>
>> For Each DrRowAlerToAcv In TmpAlertSubRows.Rows
>> Dim strAlertMsg As String =
>> TmpAlert.AlertMessage.ToString(DrRowAlerToAcv)
>>
>> Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin
>> Alert...", 3000)
>> NewAlrtfrm.ShowInTaskbar = False
>> NewAlrtfrm.Show()
>>
>>
>>
>>
>> RaiseEvent showAlert(strAlertMsg)
>> Call FlagRecord(TmpAlert, DrRowAlerToAcv)
>> Next
>> Next
>>
>> End Sub
>>
>> End Class
>>
>>
>>
>> Into the Search Sub you may see that im instancing the form AlertSpace :
>>
>> Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin Alert...", 3000)
>>
>> When this line is executed: The form is showed however, the paint events
>> (form.paint) and (panel1.paint) ; (im using a paint object into to) are
>> not
>> executed ..
>>
>> =( Thank you very much for your help ; and any advice you can give..
>>
>>
>
>



Re: Paint event don't Work by JosueAvilaMendoza

JosueAvilaMendoza
Fri Jan 20 14:48:02 CST 2006

Hi Stoitcho
Finally I got the solution.. tks for your help , it was really a big Hand ..

Josue





"Stoitcho Goutsev (100)" wrote:

> Actually there is a easier solutions than the one I already suggested. I
> just forgot to mention them with my last post.
>
> 1. Use System.Windows.Forms.Timer if timer accuracy is not an issue for you.
>
> 2. Use System.Timers.Timer instead of System.Threading.Timer. Timers.Timer
> has a property - SynchronizingObject that you can set with a reference to a
> control form the main UI and it will marshal the event for execution in the
> UI thread for you.
>
>
> --
> HTH
> Stoitcho Goutsev (100)
>
> "Stoitcho Goutsev (100)" <100@100.com> wrote in message
> news:evBMqUVFGHA.516@TK2MSFTNGP15.phx.gbl...
> > Josue,
> >
> > You cannot show a form like this. The thread that executes the event is
> > not an UI thread. You need to either create a UI thread or create the form
> > in the main UI thread.
> > Starting a message pump in the thread where timer event is fired is not a
> > good idea because this thread is borrowed from the thread pool where the
> > threads are limited number, thus using the main thread is better approach.
> >
> > To create the form in the main thread you need to have reference to some
> > control from the main UI (say reference to the form). Basically this work
> > as follows (I write this in c# because I'm not very comfortable with the
> > VB syntax.
> >
> > void CreateAForm(Param1, Param2, ....)
> > {
> > if(aControl.InvokeRequired)
> > {
> > SomeDelegate someDelegate = new SomeDelegate(CreateAForm)
> > // aControl is a reference to a control from the main UI
> > aControl.Invoke(someDelegate, new object[]{param1, param2, ....});
> > return; //NOTE: This return is very important
> > }
> >
> > <All the code for creating, initializing and showing the new form>
> > }
> >
> >
> > --
> > HTH
> > Stoitcho Goutsev (100)
> >
> >
> >
> > "Josue Avila Mendoza" <JosueAvilaMendoza@discussions.microsoft.com> wrote
> > in message news:68229EAF-187C-4264-8E36-210C1849BF0E@microsoft.com...
> >> Hi
> >> It is not posible for me to acces into the link ; i Think is Firewall
> >> issues
> >> ..
> >> But Look this is a part from my class code ..
> >>
> >> Public Class AlertsEngine
> >> Private LCCollectionAlerts As Alerts
> >> Private LCDCAlertEngine As DCAlertEngine = New DCAlertEngine
> >> Private InstanceSearcher As New TimerCallback(AddressOf Me.Search)
> >> Private LCInterval As Integer = 8000
> >> Private StateTimer As Timer
> >> Public Event showAlert(ByVal strAlertMessage As String)
> >>
> >>
> >> Sub New(ByVal ObjAlertClct As Alerts)
> >> Me.LCCollectionAlerts = ObjAlertClct
> >> End Sub
> >>
> >> Public Function Start()
> >> Me.StateTimer = New Timer(InstanceSearcher, Nothing, LCInterval,
> >> 250)
> >> StateTimer.Change(250, LCInterval)
> >> End Function
> >>
> >> Public Function [Stop]()
> >> If Not Me.StateTimer Is Nothing Then
> >> StateTimer.Change(0, 0)
> >> End If
> >> End Function
> >>
> >>
> >> Private Sub Search(ByVal Stateinfo As Object)
> >>
> >> Dim TmpAlert As Alert
> >> Dim DrRowAlerToAcv As DataRow
> >>
> >> For Each TmpAlert In Me.LCCollectionAlerts
> >> Dim TmpAlertSubRows As DataTable =
> >> TmpAlert.GetRecordsInAlertsOn()
> >>
> >> For Each DrRowAlerToAcv In TmpAlertSubRows.Rows
> >> Dim strAlertMsg As String =
> >> TmpAlert.AlertMessage.ToString(DrRowAlerToAcv)
> >>
> >> Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin
> >> Alert...", 3000)
> >> NewAlrtfrm.ShowInTaskbar = False
> >> NewAlrtfrm.Show()
> >>
> >>
> >>
> >>
> >> RaiseEvent showAlert(strAlertMsg)
> >> Call FlagRecord(TmpAlert, DrRowAlerToAcv)
> >> Next
> >> Next
> >>
> >> End Sub
> >>
> >> End Class
> >>
> >>
> >>
> >> Into the Search Sub you may see that im instancing the form AlertSpace :
> >>
> >> Dim NewAlrtfrm As AlertSpace = New AlertSpace("Testin Alert...", 3000)
> >>
> >> When this line is executed: The form is showed however, the paint events
> >> (form.paint) and (panel1.paint) ; (im using a paint object into to) are
> >> not
> >> executed ..
> >>
> >> =( Thank you very much for your help ; and any advice you can give..
> >>
> >>
> >
> >
>
>
>