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 said:
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..