Click here to Skip to main content
15,894,343 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Threading/GIF animation Pin
Amlanjyoti Saikia9-Feb-13 1:53
Amlanjyoti Saikia9-Feb-13 1:53 
AnswerRe: Threading/GIF animation [Solved] Pin
Dave Kreskowiak9-Feb-13 3:44
mveDave Kreskowiak9-Feb-13 3:44 
GeneralRe: Threading/GIF animation [Solved] Pin
Amlanjyoti Saikia1-Mar-13 19:20
Amlanjyoti Saikia1-Mar-13 19:20 
GeneralRe: Threading/GIF animation [Solved] Pin
Dave Kreskowiak2-Mar-13 3:56
mveDave Kreskowiak2-Mar-13 3:56 
AnswerRe: Threading/GIF animation [Solved] [Updated Code] Pin
Amlanjyoti Saikia1-Mar-13 19:21
Amlanjyoti Saikia1-Mar-13 19:21 
Questionhow to access the stream of the ip camera via c# using Aforge Pin
Glendonz8-Feb-13 22:56
Glendonz8-Feb-13 22:56 
AnswerRe: how to access the stream of the ip camera via c# using Aforge Pin
OriginalGriff8-Feb-13 23:04
mveOriginalGriff8-Feb-13 23:04 
GeneralRe: how to access the stream of the ip camera via c# using Aforge Pin
Glendonz13-Feb-13 19:31
Glendonz13-Feb-13 19:31 
Questionproperty of network base software? Pin
Edalat_20118-Feb-13 21:00
Edalat_20118-Feb-13 21:00 
AnswerRe: property of network base software? Pin
Richard MacCutchan8-Feb-13 23:01
mveRichard MacCutchan8-Feb-13 23:01 
GeneralRe: property of network base software? Pin
Edalat_20119-Feb-13 3:28
Edalat_20119-Feb-13 3:28 
GeneralRe: property of network base software? Pin
Dave Kreskowiak9-Feb-13 3:38
mveDave Kreskowiak9-Feb-13 3:38 
QuestionHow to import data from OpenOffice to DataTable/DataSet Pin
devchina8-Feb-13 19:43
devchina8-Feb-13 19:43 
AnswerRe: How to import data from OpenOffice to DataTable/DataSet Pin
Richard MacCutchan8-Feb-13 23:00
mveRichard MacCutchan8-Feb-13 23:00 

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.