Click here to Skip to main content
15,905,414 members
Home / Discussions / C#
   

C#

 
AnswerRe: multiplication Pin
Dave Kreskowiak9-Feb-13 8:25
mveDave Kreskowiak9-Feb-13 8:25 
AnswerRe: multiplication Pin
PIEBALDconsult9-Feb-13 10:26
mvePIEBALDconsult9-Feb-13 10:26 
QuestionHow to change a cs file in an existing project? (to combine different projects) Pin
gibsray9-Feb-13 5:50
gibsray9-Feb-13 5:50 
AnswerRe: How to change a cs file in an existing project? (to combine different projects) Pin
Dave Kreskowiak9-Feb-13 6:22
mveDave Kreskowiak9-Feb-13 6:22 
Questionhow to cache data with dictionary in Pin
mhd.sbt9-Feb-13 4:34
mhd.sbt9-Feb-13 4:34 
GeneralRe: how to cache data with dictionary in Pin
PIEBALDconsult9-Feb-13 5:36
mvePIEBALDconsult9-Feb-13 5:36 
GeneralRe: how to cache data with dictionary in Pin
Eddy Vluggen9-Feb-13 8:25
professionalEddy Vluggen9-Feb-13 8:25 
AnswerRe: how to cache data with dictionary in Pin
Dave Kreskowiak9-Feb-13 6:25
mveDave Kreskowiak9-Feb-13 6:25 
GeneralRe: how to cache data with dictionary in Pin
mhd.sbt14-Feb-13 23:40
mhd.sbt14-Feb-13 23:40 
GeneralRe: how to cache data with dictionary in Pin
Dave Kreskowiak15-Feb-13 1:58
mveDave Kreskowiak15-Feb-13 1:58 
AnswerRe: how to cache data with dictionary in Pin
Abhinav S9-Feb-13 21:06
Abhinav S9-Feb-13 21:06 
QuestionHow to add three columns in shpae file using c# Pin
devchina8-Feb-13 23:49
devchina8-Feb-13 23:49 
AnswerRe: How to add three columns in shpae file using c# Pin
Richard MacCutchan9-Feb-13 0:10
mveRichard MacCutchan9-Feb-13 0:10 
GeneralRe: How to add three columns in shpae file using c# Pin
devchina9-Feb-13 0:49
devchina9-Feb-13 0:49 
GeneralRe: How to add three columns in shpae file using c# Pin
Richard MacCutchan9-Feb-13 0:52
mveRichard MacCutchan9-Feb-13 0:52 
AnswerRe: How to add three columns in shpae file using c# Pin
Eddy Vluggen9-Feb-13 0:18
professionalEddy Vluggen9-Feb-13 0:18 
Questionlinq to list and lamda expresion Pin
mhd.sbt8-Feb-13 23:44
mhd.sbt8-Feb-13 23:44 
AnswerRe: linq to list and lamda expresion Pin
Eddy Vluggen9-Feb-13 0:14
professionalEddy Vluggen9-Feb-13 0:14 
GeneralRe: linq to list and lamda expresion Pin
mhd.sbt9-Feb-13 1:23
mhd.sbt9-Feb-13 1:23 
AnswerRe: linq to list and lamda expresion Pin
N a v a n e e t h9-Feb-13 0:23
N a v a n e e t h9-Feb-13 0:23 
GeneralRe: linq to list and lamda expresion Pin
Richard Deeming11-Feb-13 1:40
mveRichard Deeming11-Feb-13 1:40 
QuestionThreading/GIF animation [Solved] Pin
Amlanjyoti Saikia8-Feb-13 22:58
Amlanjyoti Saikia8-Feb-13 22:58 
Hi,
I am working on a application that creates a report with pretty complicated graphics, which no doubt takes a lot of time. In order to convince the users that the program is actually working and has not hanged itself up, I thought of using a small window that shows a spinning gif image along with some message asking them to wait for the process to complete.

This is how I have implemented the functionality
C#
class MainForm
{
    Thread LenghtyOperationThread;

    //Some Code
    
    private void buttonCreateReport_Click(object sender, EventArgs e)
    {
      LengthyOperationThread = new Thread(() => { CreateReport(); });
      RunLengthyThread();
      ShowReport();
    }

    //Other code
}

And this is the function that deal with showing the wait form
C#
private void RunLengthyThread()
{
   WaitForm wf = new WaitForm();
   this.Enabled = false;
   wf.Show();
   LengthyOperationThread.Start();
   LengthyOperationThread.Join();
   wf.Close();
   this.Enabled = true;
}


Everything works as I wanted, except a few minor bugs like the MainForm not getting focus after the WaitForm is closed.

The problems I am facing and don't have a clue about are these -
1. The gif image does not animate. All I can guess is that the WaitForm window is also waiting for the main thread to join the LenghtyOperationThread before animating the gif.
2. I cannot figure out a way to return focus to the MainForm window once the WaitForm window closes.

Help me out? Please?

SOLVED
Thanks for pointing out the errors. Both problems are now solved.

Modified code follows -

C#
private void RunLengthyThread()
{
   WaitForm wf = new WaitForm();
   Thread WaitFormThread = new Thread(() => {
                WaitForm wf = new WaitForm();
                wf.ShowDialog();
            });

   LengthyOperationThread.Start();
   LengthyOperationThread.Join();

   try
   {
     WaitFormThread.Abort();
   }
   catch{ }
}



UPDATE. DON'T DO WHAT I DID ABOVE. THIS CODE WILL GIVE YOU Threading and GDI+ exceptions randomly. I am not sure how, but this code also causes the application to slow down after a few hours. Memory and processor usage will remain minimal, as seen in task manager or process hacker. Dead | X|

New code is posted below. Long story short, use a backgroundwoker.

modified 2-Mar-13 1:26am.

AnswerRe: Threading/GIF animation Pin
N a v a n e e t h9-Feb-13 0:17
N a v a n e e t h9-Feb-13 0:17 
GeneralRe: Threading/GIF animation Pin
Amlanjyoti Saikia9-Feb-13 1:24
Amlanjyoti Saikia9-Feb-13 1:24 
AnswerRe: Threading/GIF animation Pin
Eddy Vluggen9-Feb-13 0:17
professionalEddy Vluggen9-Feb-13 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.