Yes, I disable the timer control until the function in the dowork is
complete.
i just edited for clarity
On Aug 31, 11:30 pm, "Arsalan Tamiz" <[EMAIL PROTECTED]> wrote:
> As Andrew said that you didn't mention the problem. However in your Timer
> Tick Event handler you have started the Background worker but what if this
> Tick event is occurred between processing? Have you done this type of
> checking? The Timer Control should be disabled while the Background worker
> is doing its work or there should be multiple threads if some work needs to
> be done on every Tick.
>
> On Sun, Aug 31, 2008 at 2:20 PM, Andrew <[EMAIL PROTECTED]> wrote:
>
> > You did not say what the problem was
>
> > ~Andrew
>
> > On Aug 30, 2:24 pm, raz230 <[EMAIL PROTECTED]> wrote:
> > > I have a problem has occasionally happens in my program. The program
> > > is is a shipping system and has a scale connected to the PC with a
> > > serial cable.
>
> > > I use a background worker from inside a timer control to poll the
> > > scanner for it's weight and display it on the main form's window in a
> > > textbox control.
>
> > > The computer I develop on is a dual core machine. I'm not sure if
> > > this has any bearing but I can tell that I do not observe the problem
> > > at all in the development environment.
>
> > > I have this tick event on the main form:
>
> > > If My.Settings.UseScale = True Then
> > > Try
> > > BackgroundWorker1.RunWorkerAsync()
> > > Catch ex As Exception
> > > BackgroundWorker1.CancelAsync()
> > > End Try
> > > End If
>
> > > The dowork event of the background worker looks like this
>
> > > Private Sub BackgroundWorker1_DoWork(ByVal sender As
> > > System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
> > > Handles BackgroundWorker1.DoWork
>
> > > Dim worker As BackgroundWorker = CType(sender,
> > > BackgroundWorker)
> > > e.Result = GetScaleValue() 'returns a string
>
> > > End Sub
>
> > > And in the GetScaleValue function- the code that polls the scale looks
> > > like this
>
> > > Public Function GetScaleValue() as String
>
> > > Serial.Write("W") 'send "W" and read the reply
> > > txtDefaultWeight.Text = Serial.ReadExisting.ToString 'this is the
> > > reply
>
> > > If txtDefaultWeight.Text.Length > 2 Then 'clean up the reply
> > > With txtDefaultWeight
> > > .Text = .Text.Remove(0, 1)
> > > .Text = .Text.Remove(txtDefaultWeight.Text.Length - 1, 1)
> > > End With
> > > End If
>
> > > End Function
>
> > > Is this the correct way to handle this? I'm sure there's more than
> > > one way, but is what I have wrong or flawed?
>
> > > Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---