CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Button/busyindicator in other than Click Event

    Hi all,

    Oke hope I can make myself clear...

    In a ButtonClickEvent you can change the state of a button for instance
    Like using Button.IsEnabled = true; (Or false)
    In my Button click event code I put an find file routine this routine calls an CRC32 routine
    with me so far..

    Oke when the CRC32 routine starts I want to display the busyindicator control.
    (got it from the extended wpf toolkit).
    But this Item is not accessible in the CRC32 routine (also not accessible in find file) only in
    the button click routine.

    how do I make this control accessible in the CRC32 routine?

    regards,

    ger

  2. #2
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    did some digging,

    need to change

    public static bool CRCChecker(string Filename, string HashIn)

    and change this;

    if (CRCChecker(FileName, InstallCRC) == true)


    regards

    Ger
    Last edited by TBBW; January 3rd, 2014 at 04:16 PM. Reason: edit

  3. #3
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    Hi all,


    so;

    Code:
    private void InstallClick(object sender, RoutedEventArgs e)
                    | 
                    |-    BusyIndicator.IsBusy  = true;     //Valid here !!!
                    |
                    |->  public static Nullable <bool> GetDriveAndFile(InstallerMode Mode)
                                              |
                                              |-     BusyIndicator.IsBusy  = true;     //NOT Valid here !!!
                                              |
                                              |
                                              |-> public static bool CRCChecker(string Filename, string CRC)
                                                                         |
                                                                         |
                                                                         |-  BusyIndicator.IsBusy  = true;     //Aslo NOT Valid here !!!
                                                                         |
                                                                     <-|
    How can I make this work?

    Regards,

    Ger
    Last edited by TBBW; January 4th, 2014 at 07:48 AM.

  4. #4
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Button/busyindicator in other than Click Event

    If BusyIndicator is an instance variable or a property, then it's because those two methods, GetDriveAndFile() and CRCChecker(), are static.
    If you can change the code of those methods, then either make them non-static, or add to each an additional parameter, e.g. GetDriveAndFile(InstallerMode Mode, BusyIndicator Busy), and then pass along the BusyIndicator available from within InstallClick().

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Button/busyindicator in other than Click Event

    Does the crc routine supply update and/or completed events? If so, put the ui button state code in there.

  6. #6
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    The CRC routine only returns a false or true value, no updates/events just a math routine
    I want to switch on the busyindicator when enetering the CRC routine and turn it off when leaving the CRC.

    VS does not let me create GetDriveAndFile(InstallerMode Mode, BusyIndicator Busy)

    the BusyIndicator is in xaml like this;

    <ext:BusyIndicator x:Name="BusyIndicator" BusyContent="Verifying" Foreground="Black"/>

    using;

    xmlns:ext="http://schemas.xceed.com/wpf/xaml/toolkit"

    I have to make the busyindicator available throughout the window class, not just in the click-event(s)
    Correct?

    regards,

    Ger
    Last edited by TBBW; January 5th, 2014 at 01:07 PM. Reason: editorial

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Button/busyindicator in other than Click Event

    Wrap the CRC routine in a BackgroundWorker class and handle the RunWorkerCompleted event. Set the BusyIndicator state before starting the thread and reset it in the RunWorkerCompleted event handler.

  8. #8
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    thanks for the info Arjay, will have a go on the backgroundworker.

    in the mean while I found this;

    WPF busy indicator implementation with singleton pattern
    see attachment;

    when I use it, using;

    BusyIndicatorManager.Instance.ShowBusy(1, "Please wait ");
    (I mean not using the sample project, but in my project)

    I do not get to see the control right away?
    Can it only be displayed in an event case?


    regards,

    ger

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Button/busyindicator in other than Click Event

    Unfortunately that sample requires additional references that I don't have access to.

  10. #10
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    what do you need?
    I will beam it up!

    regards,

    ger

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Button/busyindicator in other than Click Event

    The two non standard referenced assemblies.

  12. #12
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    the assemblies

    Ger.
    Attached Files Attached Files

  13. #13
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    Hi all,

    Working on the background thread option from Arjay, does not give me the wanted result, yet.
    Apart from that; I came to the conclusion that a VISUAL state change is done after the last bracket.
    see code;
    Code:
    private void InstallClick(object sender, RoutedEventArgs e)   //Install Button click 
            {
                BusyIndicator.IsBusy = true;
                do some time consuming work, last for about 5 sec.
            }
    in the first line the busyindicator is set to true, but the change is not visible!
    the change is visible after the "do some time etc...." so when the "program pointer" passes the closing bracket.

    Is there a way to make the change visible right away? (using something like update/redraw or stuff like that).

    Thanks,

    Ger

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Button/busyindicator in other than Click Event

    Quote Originally Posted by TBBW View Post
    Is there a way to make the change visible right away? (using something like update/redraw or stuff like that).
    You are missing the point - don't block the UI thread.

  15. #15
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Button/busyindicator in other than Click Event

    Hi,

    I do understand the blocking of the UI thread.

    using the background gives me an unstable program.
    If I runs it 10 times it crashes 2 times randomly.

    This is my "problem";
    Pushing/clicking the install button results in the following
    - Find File.
    - Do a CRC check
    - Run it

    during the find file portion the window state is normal (with a OpenFileDialog on top of it, when the File is not at the expected place)
    during the CRC check the window shows an isbusy indications
    during the execution of the file the window state is minimized.

    I also had a look at async/await method so far no luck.

    regards,

    ger

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured