Help with streamline program.

DouglasBell

Active member
Joined
Aug 16, 2011
Messages
38
Programming Experience
Beginner
Hi All

I have created a simple touchscreen system that inserts a value into a local SQL database depending on the button pressed.

The buttons are generated dynamically from an Ini file. So I can have this touchscreen on lots of systems and only need to change the ini file for different buttons.

I am not much of a programmer so I used google and other sources to help me create the system, but the more buttons the users require the more cumbersome my ini file becomes to write. Was hoping that you could take a look at my example project and help me come up with an easier solution for dynamically creating the buttons, since I already have local SQL databases maybe using a table for the buttons instead, not sure.

The project is written in VS 2005.

Cheers

Dj
 

Attachments

  • Buttonini.zip
    526 bytes · Views: 24
  • ButtonTest.zip
    16.3 KB · Views: 22
Last edited by a moderator:
Hi All

Just been asked another question.

My management now want to have a central screen that displays the current status of all the touchscreens, the information has to be as real time as possible.

So I wrote a view on the local SQL database that basically collects all the information the management are looking for then I used a timer on the Touchscreen that takes this information and inserts the data into a central SQL Database, the central screen then uses this information for display. I have a couple of problems with this.

1) The timer doing updates to the central database is causing havoc with the touchscreen itself, screen freezes ect when doing the updates, so every 2 seconds the screen freezes for a split second. Also if there is a lot of traffic on the LAN or the central SQL server is being used heavly then the delays are longer.

2) At the moment my timer deletes all the entries from the Central SQL server for that touchscreen then transfers the data across using the view I created, obviously as the day progresses more and more information is going to be passed across. The way I am doing it is very cumbersome and looks even worse on the Central screen as all its information dissapears until it has been updated.

1) How do I overcome the problems with the screen freezing, would writing to an XML file be less intensive, is it possible to have the local SQL initiate the copy from say a trigger or table change and take it away from the screen itself?

2) What is the correct method to use for record transfer to a central server, have another field on my local table that basically gets an update flag when the data is transferred and my view then ignores all information that has this update flag?

Cheers

Dj
 
Hi,

With regards to your first post, I am sorry but I am not downloading anything. That said, whether you use an INI file or a Database to configure your buttons is purely down to what you feel is the easiest solution for you to maintain. I have done this a few times and I prefer a database but that's just me.

With regards to your second post, I am sure you have already guessed that you are getting your screen freezing issues due to all the processing going on in your project. What you need to do here to keep the UI thread responsive is to move all your Database processing routines to a secondary thread. To achieve this have a look at the BackgoundWorker class:-

BackgroundWorker Class (System.ComponentModel)

Hope that helps.

Cheers,

Ian
 
Hi

Had a look at the BackgroundWorker Class and its a bit beyond me, so I am a little stuck.

I have a timer TmrUploadResults that every 5 seconds it calls a sub UploadResults. Upload results is basically an update query to the central server. How would I use the Background worker to take the strain of the UI so the UploadResults doesnt freeze my UI?

Cheers

Dj
 
Hi,

Here is an example of how you can use a BackgroundWorker with a Timer to do what you are looking to do. Add a Timer, ProgressBar, ListBox and Button (called btnCancelBGWorker) to a Form and copy the code below to that Form. If you read through the comments carefully you should be able to work out what is going on here and understand how you can use this yourself in your own project.

VB.NET:
Public Class Form1
 
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'To use these methods correctly you need to set both WorkerReportsProgress and WorkerSupportsCancellation to True
 
    'Disable cancellation of the BackgroundWorker since it is not yet running
    btnCancelBGWorker.Enabled = False
 
    'Set the progress bar Maximum Value property to 100 - (just for show in this example)
    ProgressBar1.Maximum = 100
 
    'Start The timer on the UI Thread to pick up your Data every 5 Seconds (in theory - see comment below)
    With Timer1
      .Interval = 5000
      .Enabled = True
    End With
  End Sub
 
  Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    'Since we do not know how long the Database routine will take - lets turn the timer off so that we
    'DO NOT have multiple Threads trying to update your Data at the same time. Once the BackgroundWorker
    'has finished it's work we will then turn the Timer back on to continue to update every 5 seconds
    Timer1.Enabled = False
 
    'Reset the progress bar for the BackgroundWorker
    ProgressBar1.Value = 0
 
    'Now Enable cancellation of the BackgroundWorker since you may want to cancel it while it is running
    btnCancelBGWorker.Enabled = True
    'Now run the BackgroundWorker
    BackgroundWorker1.RunWorkerAsync()
  End Sub
 
  'This method is executed in a worker thread when you call BackgroundWorker1.RunWorkerAsync
  Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    'This is considerered best practice to allow handling of multiple background workers with the same method
    Dim myWorker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker)
 
    'Now lets do some time consuming work which would normally freeze the UI Thread
    For i As Integer = 1 To 100
      'Check to see if you have cancelled the BackgroundWorker process
      If myWorker.CancellationPending Then
        'The user has cancelled the background operation.
        e.Cancel = True
        Exit For
      Else
        'You can Raise the ProgressChanged event in the UI thread
        'You can pass any object type to the userState property of the ReportProgress method which
        'Therefore allows you to display any newly created objects in the current thread as 
        'the background worker is functioning - here we just pass a string back to the UI thread
        myWorker.ReportProgress(i, i & " iterations complete")
 
        'Perform some time-consuming operation here.
        Threading.Thread.Sleep(100)
      End If
    Next i
  End Sub
 
  'This method is executed in the UI thread when you call myWorker.ReportProgress above
  Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    'Update the progress bar and display whatever you want
    ProgressBar1.Value = e.ProgressPercentage
    ListBox1.Items.Insert(0, e.UserState)
  End Sub
 
  'This method is executed in the UI thread when the BackgroundWorker has completed whatever it is doing
  Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    'Check to see if the BackgroundWorker Was cancelled and do something
    If e.Cancelled Then
      'The background operation was cancelled.
      ListBox1.Items.Insert(0, "Operation Cancelled")
    Else
      ListBox1.Items.Insert(0, "Operation Completed")
      'Start the Timer again and Disable the Cancel Button so you can continue doing your work every 5 seconds
      btnCancelBGWorker.Enabled = False
      Timer1.Enabled = True
    End If
  End Sub
 
  Private Sub btnCancelBGWorker_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelBGWorker.Click
    'If you cancel the BackgroundWorker then check to see if it is busy and Cancel it
    If BackgroundWorker1.IsBusy Then
      BackgroundWorker1.CancelAsync()
    End If
  End Sub
End Class

As you will see, when you run this the UI Thread stays nice and responsive so that you can continue to do whatever else it is that you want on the UI Thread.

Hope that helps.

Cheers,

Ian
 
Back
Top