473,324 Members | 2,535 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,324 software developers and data experts.

Problems starting a Timer Programmatically within a BackgroundWorker

Problems starting a Timer Programmatically within a BackgroundWorker.

I am trying to start a Timer inside a Backgroundworker. I want to start the BackGroundWorker and then have a timer tick a calculation reppeting inside the BackGroundWorker. The Code below seems to work ok for sending back the informaton "DoWork - Enter" and "DoWork - Exit, but the Timer "Timer_Ping" is newer ticked and the line "Time - Tick" is newer send back.

Why is my timer not starting? What am I doing wrong?

Peter Schwennesen

Expand|Select|Wrap|Line Numbers
  1. Imports System.Text
  2. Imports System.Drawing
  3. Imports System.ComponentModel
  4. Imports System
  5.  
  6. Public Class PingVindow
  7.     Inherits TableLayoutPanel
  8.  
  9.     Private TableLayoutPanel_Ping As TableLayoutPanel = CType(Me, TableLayoutPanel)
  10.     Private ListBox_PingResult As New ListBox
  11.  
  12.     Private WithEvents BackgroundWorker_Ping As New BackgroundWorker
  13.  
  14.     Public Sub New()
  15.         With ListBox_PingResult
  16.             .Dock = DockStyle.Fill
  17.             .IntegralHeight = False
  18.             .Font = New Font("Courier New", 9.0!, FontStyle.Regular)
  19.             .Items.Add("Test Started")
  20.         End With
  21.  
  22.         With TableLayoutPanel_Ping
  23.             .RowCount = 1
  24.             .RowStyles.Add(New RowStyle(SizeType.Percent, 100))
  25.             .ColumnCount = 2
  26.             .ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 50))
  27.             .ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 50))
  28.             .Controls.Add(ListBox_PingResult, 0, 0)
  29.             .Dock = DockStyle.Fill
  30.         End With
  31.  
  32.         BackgroundWorker_Ping.WorkerReportsProgress = True
  33.         BackgroundWorker_Ping.RunWorkerAsync()
  34.     End Sub
  35.     '------------------------------------------------------------------------------------------------------
  36.     Private Sub BackgroundWorker_Ping_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker_Ping.DoWork
  37.         BackgroundWorker_Ping.ReportProgress(0, "DoWork - Enter")
  38.         Dim Timer_Ping As New Timer
  39.         AddHandler Timer_Ping.Tick, AddressOf Timer_Ping_Tick
  40.         Timer_Ping.Interval = 1000
  41.         Timer_Ping.Enabled = True
  42.         Timer_Ping.Start()
  43.         BackgroundWorker_Ping.ReportProgress(0, "DoWork - Exit")
  44.     End Sub
  45.  
  46.     Private Sub BackgroundWorker_Ping_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker_Ping.ProgressChanged
  47.         Me.ListBox_PingResult.Items.Add(e.UserState.ToString)
  48.     End Sub
  49.  
  50.     '------------------------------------------------------------------------------------------------------
  51.     Public Sub Timer_Ping_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
  52.         BackgroundWorker_Ping.ReportProgress(0, "Timer - Tick")
  53.     End Sub
  54.  
  55. End Class
  56.  
Aug 25 '08 #1
0 1842

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rajesh Abraham | last post by:
I have a Windows Service and in the OnStart, I am initializing the BusinessLayer Object and calling a method of the object, which normally takes about 10 mts to finish execution. Now when I...
4
by: Anthony Boudouvas | last post by:
Hi to all, i have a form with 2 System.Windows.Forms.Timer objects. One fire every 5 seconds and the other every 10 seconds, the both take actions in two hashtables declared in same form. ...
0
by: tshad | last post by:
I have a Windows Service I created that just sets a timer and writes to EventLog every 10 seconds. It installed fine and it actually starts. But it says it doesn't. The progress bar shows the...
3
by: Nathan | last post by:
Somebody help please, I am desperate for help as I've battled this problem for 3 days now! :( I have an application (NT Service) that uses 2 threads... one worker-thread (i.e. always running)...
0
by: Dominick Baier | last post by:
Hi, impersonation effectively means that you setting your current thread in the security context of your client. When you invoke a web service asynchronously, .net grabs a thread from the...
7
by: Jayyde | last post by:
Is there any way to accomplish this? The forms _Load event fires off several other small ones that I'd like to track time for. I can't get either the Mdi Parent form's timer _Tick event or the...
7
by: Joseph Geretz | last post by:
I have a Service which runs OK, but I'm abviously not starting it properly. In my OnStart event I commence a long running process which polls a database table and performs various processing. Since...
4
by: =?Utf-8?B?U3ZlbiBXLg==?= | last post by:
Hi Newsgroup, I am developing a C# Windows Forms application that launches processes within a background worker.. The processes seem to have a memory limit of about 278mb. Some proccesses...
2
by: Johnny Jörgensen | last post by:
I've got a process I want to run in a thread separate from my main application thread, so I've used a backgroundworker component, and in frmMain.Load I invoke the code using...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.