1

I'm using a background image to change the language of my application, it needs to show a gif in a picturebox while it is changing the language.

The code I use looks as follow:

    private void pbNL_Click(object sender, EventArgs e)
    {
        var bwchangelanguageNL = new BackgroundWorker();
        bwchangelanguageNL.DoWork += bwchangelanguageNL_DoWork;
        bwchangelanguageNL.RunWorkerCompleted += bwchangelanguageNL_RunWorkerCompleted;
        bwchangelanguageNL.RunWorkerAsync();
    }

    void bwchangelanguageNL_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        pbLoading.Visible = false;
    }

    void bwchangelanguageNL_DoWork(object sender, DoWorkEventArgs e)
    {
        pbLoading.Visible = true;
        const int countryLanguage = 1;
        ChangeLanguage(countryLanguage);         
    }

When I press the pbNL button(Click event) nothing happens. Why does nothing happen? The backgroundworker gets started with RunWorkerAsync on button click.

The picturebox with gif doesn't show up and the language doesn't change.

Edit

The DoWork event and the RunWorkerCompleted event get both called, so calling the events isn't the problem.

Max
  • 12,622
  • 16
  • 73
  • 101
  • could it be what language changes too fast (so no gif), but there is an error in changing language (or `1` is current/already selected language), so this doesn't occurs too? – Sinatr May 13 '13 at 14:41
  • The code wasn't in a backgroundworker at first, but it was pretty slow, so I did put it in a backgroundworker, but now the language isn't even changing, it did change when it wasn't in a backgroundworker, but it was slow that way. – Max May 13 '13 at 14:46
  • to fix gif issue - put `Thread.Sleep` inside `ChangeLanguage`. – Sinatr May 13 '13 at 14:56
  • This is not exactly a duplicate but [check this... very similar][1] [1]: http://stackoverflow.com/questions/12618575/cross-thread-operation-not-valid-control-label1-accessed-from-a-thread-other – user2315985 May 13 '13 at 15:11
  • Not even close to a duplicate, the only matching part is the use of a backgroundworker. – Max May 13 '13 at 15:13
  • You aren't supposed to be changing GUI elements from the background thread. Do you have a Try/Catch inside ChangeLanguage()? If so, it might simply be catching the [cross-thread](http://msdn.microsoft.com/en-us/library/ms171728.aspx) exception and immediately exiting out of your DoWork() method. – Idle_Mind May 13 '13 at 15:24
  • It doesn't give me an exception, so how should I manage the try/catch then. – Max May 13 '13 at 15:30
  • please add you code for `ChangeLanguage(countryLanguage);` – Saagar Elias Jacky Apr 08 '15 at 01:15

0 Answers0