473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

VB.NET Background Process

Howdy folks, I have a sleeping thread that runs every 20 seconds or so to
check for messages from a database message store.
When it detects an un-acknowledged message, I am firing off a notification
routine that raises a toaster popup.

The problem is that since it is in a thread, the code keeps going right
through that event and it doesn't allow the app to spawn the alert window
(see attached code) and I end up with a little piece of the alert window and
then it just craps out during the next iteration.

Can someone help fix this or provide a better method of having this sleeper
thread go without interupting the normal program execution?

Thanks!
Derek

My (I know it's ugly cause I am just trying to see if it can get it to work)
code:

'On the form load
u = New Thread(AddressOf message_sleeper)
u.Start()
....
end sub

Private Sub message_sleeper()
Dim i As Integer = 0
Do While True
process_client_messages()
Thread.CurrentThread.Sleep(15000)
Loop
End Sub

Private Function process_client_messages()
Dim cmd As New SqlCommand
Dim intRowsAff1 As Integer
Dim SQLStr1 As String
Dim dr As SqlDataReader
Dim messages As New ArrayList
Dim thismessage As String
Dim thisguid As String
'Get unacknowledged messages
cmd.CommandTimeout = 60
cmd.Connection = Global.conn
cmd.CommandType() = CommandType.Text
cmd.CommandText = "Select id, message from client_messages WHERE
hostname = '" + myhostname.ToString + "' AND ack = '0'" 'myhostname globally
defined
Try
Global.conn.Open()
dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
While dr.Read
thismessage = dr(1).ToString
messages.Add(thismessage.ToString)
End While
Catch ex As Exception
Dim oopsy As New ErrorHandler("Client message processor Get
Messages: ", ex.Message, ex.StackTrace, ex.GetType.ToString)
Dim newmessage As New MessageProcessor
newmessage.process_message(oopsy.HelpLink.ToString )
Finally
Global.conn.Close()
End Try

'Display the messages via alert if it is not a CMD -->This is what gets
stuck cause the thread just blows right past it :-(
Dim i As Integer = 0
For i = 0 To messages.Count - 1
Dim newmessage As New MessageProcessor
newmessage.process_message(messages(i).ToString)
Next
End Function
Thank you!!!!!!
Nov 20 '05 #1
2 9296
Hi,
I had a situation slightly similar to this. The way i solved it was to
1. create a new class and add raiseevents for the events that you want to
create popups for
2. make sure that the class that starts the thread has a withevents for the
class/
3. add handlers to the form that you are calling the thread from to create
the actual popup

Hope this helps.
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Howdy folks, I have a sleeping thread that runs every 20 seconds or so to
check for messages from a database message store.
When it detects an un-acknowledged message, I am firing off a notification
routine that raises a toaster popup.

The problem is that since it is in a thread, the code keeps going right
through that event and it doesn't allow the app to spawn the alert window
(see attached code) and I end up with a little piece of the alert window
and
then it just craps out during the next iteration.

Can someone help fix this or provide a better method of having this
sleeper
thread go without interupting the normal program execution?

Thanks!
Derek

My (I know it's ugly cause I am just trying to see if it can get it to
work)
code:

'On the form load
u = New Thread(AddressOf message_sleeper)
u.Start()
...
end sub

Private Sub message_sleeper()
Dim i As Integer = 0
Do While True
process_client_messages()
Thread.CurrentThread.Sleep(15000)
Loop
End Sub

Private Function process_client_messages()
Dim cmd As New SqlCommand
Dim intRowsAff1 As Integer
Dim SQLStr1 As String
Dim dr As SqlDataReader
Dim messages As New ArrayList
Dim thismessage As String
Dim thisguid As String
'Get unacknowledged messages
cmd.CommandTimeout = 60
cmd.Connection = Global.conn
cmd.CommandType() = CommandType.Text
cmd.CommandText = "Select id, message from client_messages WHERE
hostname = '" + myhostname.ToString + "' AND ack = '0'" 'myhostname
globally
defined
Try
Global.conn.Open()
dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
While dr.Read
thismessage = dr(1).ToString
messages.Add(thismessage.ToString)
End While
Catch ex As Exception
Dim oopsy As New ErrorHandler("Client message processor Get
Messages: ", ex.Message, ex.StackTrace, ex.GetType.ToString)
Dim newmessage As New MessageProcessor
newmessage.process_message(oopsy.HelpLink.ToString )
Finally
Global.conn.Close()
End Try

'Display the messages via alert if it is not a CMD -->This is what gets
stuck cause the thread just blows right past it :-(
Dim i As Integer = 0
For i = 0 To messages.Count - 1
Dim newmessage As New MessageProcessor
newmessage.process_message(messages(i).ToString)
Next
End Function
Thank you!!!!!!

Nov 20 '05 #2
Thanks for your message - I thought that was what I was doing!? Can you
give me a code snippet to illustrate the difference in what I am doing vs.
your solution?

Thanks!
Derek

"Arun Pereira" <ar**@velcom.com> wrote in message
news:ub*************@TK2MSFTNGP12.phx.gbl...
Hi,
I had a situation slightly similar to this. The way i solved it was to
1. create a new class and add raiseevents for the events that you want to
create popups for
2. make sure that the class that starts the thread has a withevents for the class/
3. add handlers to the form that you are calling the thread from to create
the actual popup

Hope this helps.
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Howdy folks, I have a sleeping thread that runs every 20 seconds or so to check for messages from a database message store.
When it detects an un-acknowledged message, I am firing off a notification routine that raises a toaster popup.

The problem is that since it is in a thread, the code keeps going right
through that event and it doesn't allow the app to spawn the alert window (see attached code) and I end up with a little piece of the alert window
and
then it just craps out during the next iteration.

Can someone help fix this or provide a better method of having this
sleeper
thread go without interupting the normal program execution?

Thanks!
Derek

My (I know it's ugly cause I am just trying to see if it can get it to
work)
code:

'On the form load
u = New Thread(AddressOf message_sleeper)
u.Start()
...
end sub

Private Sub message_sleeper()
Dim i As Integer = 0
Do While True
process_client_messages()
Thread.CurrentThread.Sleep(15000)
Loop
End Sub

Private Function process_client_messages()
Dim cmd As New SqlCommand
Dim intRowsAff1 As Integer
Dim SQLStr1 As String
Dim dr As SqlDataReader
Dim messages As New ArrayList
Dim thismessage As String
Dim thisguid As String
'Get unacknowledged messages
cmd.CommandTimeout = 60
cmd.Connection = Global.conn
cmd.CommandType() = CommandType.Text
cmd.CommandText = "Select id, message from client_messages WHERE
hostname = '" + myhostname.ToString + "' AND ack = '0'" 'myhostname
globally
defined
Try
Global.conn.Open()
dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
While dr.Read
thismessage = dr(1).ToString
messages.Add(thismessage.ToString)
End While
Catch ex As Exception
Dim oopsy As New ErrorHandler("Client message processor Get
Messages: ", ex.Message, ex.StackTrace, ex.GetType.ToString)
Dim newmessage As New MessageProcessor
newmessage.process_message(oopsy.HelpLink.ToString )
Finally
Global.conn.Close()
End Try

'Display the messages via alert if it is not a CMD -->This is what gets
stuck cause the thread just blows right past it :-(
Dim i As Integer = 0
For i = 0 To messages.Count - 1
Dim newmessage As New MessageProcessor
newmessage.process_message(messages(i).ToString)
Next
End Function
Thank you!!!!!!


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joshua Beall | last post by:
Hi All, I am working on a mailing list program for a client, and I am wondering what tbe hest way to deal with script timeouts is. I realize that I could use set_time_limit() to increase the...
1
by: Ravi Tallury | last post by:
Hi We are running a java process in the background on a aix 5.2, jdk1.31. The jvm core dumps on occasion and i would like to debug the issue. Reading through documentation, issuing the kill -30...
3
by: Jenkins | last post by:
I want to start a perl pgm in the background on my hosts web server as a stand-alone process. I only have ftp access. What I've done, so far, is: 1) created the actual background perl script,...
0
by: Gomaw Beoyr | last post by:
Hello The book "C# Black Book" chapter about Threads says that a "background thread" cannot communicate directly with a visual element, e.g. a label, and thus has to use the BeginInvoke method,...
2
by: Paul Hatcher | last post by:
I have an ASP.NET application that uses a background threads to perform a long-running process. What I'm not sure is how to track and communicate with the thread. The site is divided up into...
0
by: rlee0001 | last post by:
I have the following line of PHP code: $ret_val = system("PHP myscript.php $param1 $param2 >> output.txt &"); Obviously the intention is to run a PHP file in the background async'ly. This...
1
by: hsmcdonald | last post by:
Hello all, I have a mail function that sends parsed information to an employee distribution list. I was trying to setup a process where the admin can initiate a letter to this list, and...
5
by: awalter1 | last post by:
Hi, I develop a graphical user interface (with pyGTK) where a click on a button shall launch a program P in background. I want to get the end of this program P but I don't want that my HMI be...
33
by: bonk | last post by:
I have an application that needs to perform some background work, i.e. Logging, wich must not block the main thread. How would I basically design such a scenario? It is obvious that I should do...
2
by: Hilmar Bunjes | last post by:
Hi, I'm working on a web application in ASP.NET 3.5 and need some help with processing stuff in the background. The user who visits a web page can make reservations. Each reservation will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.