Showing a Form using a timer

G

Guest

I am creating an application that will create a notify window similar to
outlook 2003 notify popup. I am making an asyncronous remoting call using
system.thread that raises an event to show the form. However, the form shows
up as a black box and then immediately disappears when the event is called.
If I call the function through a menu item or button, it works fine. Here's
the popup code:

Private Sub ATU_RetrieveDone(ByVal e As
AsyncUpdater.AsyncUpdaterEventArgs) Handles ATU.RetrieveDone
Me.UpdateTimer.Enabled = False
If e.Forums Is Nothing Then
UpdateTopicListView(e.Results)
Else
UpdateForumListView(e.Forums)
End If
Me.UpdateTimer.Enabled = True
End Sub

Private Sub UpdateTopicListView(ByVal Topics As ResultsCollection)
For index As Integer = 0 To Topics.Count - 1
Dim LI As New ListViewItem
... Create LI Item ...
Dim NewB As New Button
If Not TopicInList(Topics.Item(index).TopicID) Then
lvNewTopics.Items.Add(LI)
End If
Next
Dim Message As String
Message = "{0} new topic updates have been retrieved from {1}"
Me.ShowPopup(String.Format(Message, Topics.Count,
ClientSettings.WebURL))
End Sub

Private Sub ShowPopup(ByVal Message As String, Optional ByVal TimeOut As
Integer = 0)
Dim displaytime As Integer
If TimeOut < 1000 Then
displaytime = ClientSettings.PopupTime * 1000
Else
displaytime = TimeOut
End If
PSound.Beep()

Dim PW As New PopupWindow
PW.SetProperties(NewMessagePopup.Blend, Message, displaytime)
PW.ShowPopup()
End Sub

And here's routine that creates the popup in a seperate windows form.

Public Sub ShowPopup()
Dim tbl As TaskBarLocation
Dim workingArea As Rectangle
Dim pt As Point

pt = New Point
pt.X = 0 : pt.Y = 0

workingArea = SystemInformation.WorkingArea
tbl = GetTaskBarLocation()

Select Case tbl
Case TaskBarLocation.Bottom
pt.X = workingArea.Right - Me.Width
pt.Y = workingArea.Bottom - Me.Height
Case TaskBarLocation.Left
pt.X = workingArea.Left
pt.Y = workingArea.Bottom - Me.Height
Case TaskBarLocation.Right
pt.X = workingArea.Right - Me.Width
pt.Y = workingArea.Bottom - Me.Height
Case TaskBarLocation.Top
pt.X = workingArea.Right - Me.Width
pt.Y = workingArea.Top
End Select

Me.Visible = False
Me.Show()
Me.Focus()
Me.Top = pt.Y
Me.Left = pt.X
Me.Visible = True
tmrStartFade.Enabled = True
End Sub


I've done some more research and it appears the problem is caused using
timers. I've used both System.Timers.Timer and System.Windows.Forms.Timer and
both give the same result, a black box that appears and then disappears. If I
call the ShowPopup subroutine by clicking a button, it displays correctly. If
the timer causes the form to be displayed, I get the black box.

Here's the logic steps used:
1) Timer.Tick event occurs
2) Tick Handler creates a new AsyncUpdater and invokes the GetUpdate method
3) GetUpdate creates a new thread and begins the remoting call
4) Once GetUpdate has completed the remoting call, the event RetrieveDone is
raised.
5) The main form handles the event causing a list view to update it's list
of items.
6) The ShowPopup method is called to display the popup.

Any help or ideas would be greatly appreciated. I can't understand why the
manual invoking (pressing a button) works but the event handler doesn't.
 
R

Richard L Rosenheim

You might try putting in an Application.DoEvents or two after the
Me.ShowPopup to give the system time to actual paint the window.

Richard Rosenheim
 
G

Guest

This helped the form show up. I placed it after the showpopup event. However,
the form disappeared almost immediately. Should I place this in the popup
class as well?
 
G

Guest

It appears that the only event that is fired by the PopUp Form is the
Form.Load event. It does not appear that any of the controls' events are ever
processed, even when calling Application.DoEvents().

Any ideas why this might be occuring?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top