dcsimg
Results 1 to 6 of 6

Thread: Looking for a status bar that updates RESPONSIVELY w/ the code.

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    49

    Looking for a status bar that updates RESPONSIVELY w/ the code.

    Hi guys, I'm looking for a component to add to my form that'll serve as a status indicator to show how far i am in the process of the code.
    I have a code that used
    StatusBarMainMenu.Panels(1).Text = "Reading serial number.." & PdSN
    StatusBarMainMenu.Panels(1).Text= " Reading something else.." & strSthElse
    StatusBarMainMenu.Panels(1).Text = "Sending unlock command.."
    ...in VB6. And the status bar at the bottom of the form refreshes just fine.
    (by refresh i mean it changes the Text whenever it's supposed to, depending on where i put these lines in the code)
    My problem arises when i upgrade these code into .NET. For one, .net doesn't have StatusBar component anymore. The code above become StatusBarMainMenu.Items.Item(0).Text = ...
    while StatusBarMainMenu being a "StatusStrip" . That's no biggy. but during runtime the status bar doesn't refresh enough. It skipped some of the text changes that're supposed to show. I tried to use: ToolStripStatusLabel1.Text = .. it didn't help.

    I think the reason could be because whatever status component i use? or it could be that the form is also occasionally freezing when the code's doing some calculation or inside a loop. in that case a bunch of DoEvents() will do. Any suggestions?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,722

    Re: Looking for a status bar that updates RESPONSIVELY w/ the code.

    What is happening is most likely that the form is told that it CAN update, but doesn't have to, and for whatever reason it has not.

    Try adding:

    StatusBarMainMenu.Refresh

    after the line where you change the text. You may be able to narrow it down even further to something like:

    StatusBarMainMenu.Items(0).Refresh

    or something like that, but I haven't used the StatusBar in too long to remember. The narrower you can get, the less that has to be redrawn when the Refresh command is hit. Refresh will force it to redraw. What it is doing is more like an Invalidate, which leaves it up to other things when to repaint.

    As for the freezing, that is almost certainly due to the things you mention. If that is problematic, consider moving the whole thing to a BackGroundWorker. VB6 didn't really multithread very easily (barely at all, really), but .NET is fully multithread capable, and the BGW is the easiest way to go about it, since it raises events on the UI thread as needed, including at completion, and as you desire to report progress. That would stop the freezing, and the reporting of progress could take care of the other part. Of course, if the freezing is currently acceptable, just the .Refresh should make the labels update better.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    49

    Re: Looking for a status bar that updates RESPONSIVELY w/ the code.

    thank you ShaggyHiker. Statusbarmainmenu.Refresh worked for the statusstrip i have on the form.
    That aside, I also have an AbortTest button on the form that reset some flags and tell the program to standby. But while the code is running the tests,it's impossible to click on that
    Aborttest button: it looks frozen. Can you point a general direction I should look into to take care of such problem? Maybe I should check out control.invoke()? or maybe some other event handling articles?
    Last edited by SandiegoSSD; Jul 13th, 2012 at 09:39 AM.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: Looking for a status bar that updates RESPONSIVELY w/ the code.

    What exactly do the tests do? Are they running some kind of loops or long blocking methods? You could run the tests in a cancellable background thread to free up the UI thread.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    49

    Re: Looking for a status bar that updates RESPONSIVELY w/ the code.

    it's communicating with an external machine thru a serial port(for that I'm using io.ports.serialport class). It does some data read/write and a few calculation with the data. Somehow all these calculation/serial communication was put in the Activate event of this TestInProgress form. I think this is also contributing to the form appearing to be frozen(except for the statusbar, which shaggyhiker solved by suggesting .refresh())

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: Looking for a status bar that updates RESPONSIVELY w/ the code.

    How do you read from the serial port (what method you call to read the data, i.e. ReadExisting, ReadLine...)? Are you handling the port's DataReceived event? Can you give us an overview of how the program works? I don't know how exactly you're currently communicate with the device, but in general it falls in to 2 categories:
    1. The device continuously sending out data. If this is the case, you just have to handle the port's datareceived event and should be good to go...
    2. You send some command to the device and it returns some data. In this case, I found it's best to use a timer and handle the port's datareceived event. When the timer ticks, you write command(s) to the port. The returned data from your device will be read and parsed in the datareceived event handler. And since datareceived event is raised on a separate thread, ther should be no UI lockups.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width