jaypee bacol

jaypee bacol

  • NA
  • 67
  • 0

Thread problem.

Jan 7 2010 10:58 PM
Hi Nikki,

Thanks for your help. Unfortunately, I have a big problem. Below are the details.


String p_outputFilePath;
String p_strDT;

This function calls the thread to create GIF file.
public void CreateGIFFile(bool blnPreview, String strDT, bool forBT)
{
                string outputFilePath "";
                outputFilePath = strDT; //This is the file name of gif created.

                string file_name = "FileGIF.txt";
                //I created this file to show the value of outputfilepath variable.
                using (TextWriter tw = new StreamWriter(Directory.GetCurrentDirectory() + "\\" + file_name, true))
                {
                    tw.WriteLine(outputFilePath);
                    tw.Close();
                }

                if ((frm_Status == null) || (!frm_Status.Visible))
                {
                    frm_Status = null;
                    frm_Status = new frmStatus();
                    frm_Status.Show();
                }

                p_blnPreview = blnPreview;
                //Process_GIF_Creation(p_outputFilePath, pstrDT, intDir);
                p_outputFilePath = outputFilePath;
                p_fullgif_filename = Program.pubstrFullGif_FileName;
                p_strDT = strDT;
                p_intDir = intDir;

               
                Thread new_thread = new Thread(new ThreadStart(Create_GIF_Thread));
                //Thread new_thread = new Thread(new ParameterizedThreadStart(Create_GIF_Thread(p_outputFilePath)));
                new_thread.Start();
}

Function to create another function to process gif creation.
private void Create_GIF_Thread()
{
            /*------------------------------------------------------------------------------------------
             * Added By: Jaypee B. Bacol
             * Date: December 29, 2009
             * Purpose: To create function to manipulate simultaneous process called threading.
             * ---------------------------------------------------------------------------------------*/
           
            lock (obj)
            {
                Process_GIF_Creation(p_fullgif_filename, p_outputFilePath, p_strDT, p_intDir, GIF_purpose, p_blnPreview, previewisopen);               
            }
}

This is the actual process of GIF creation.
private void Process_GIF_Creation(string _fullgif_filename, String outputFilePath, String strDT, int intDir, string Gif_purp, bool p_blnPreview2, bool previewisopen2)
        {

            try
            {

                if (frm_Status != null)
                    frm_Status.Invoke(frm_Status.d_DelegateSetStatus, new Object[] { "[" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "]GIF Filename:" + outputFilePath + "->Start creating gif." });

                //JAYPEE
                AnimatedGifEncoder age = new AnimatedGifEncoder();

                age.Start(outputFilePath); //This is the filename gif created.

                //-1:no repeat,0:always repeat

                if (intDir > 2)
                    age.SetDelay(110);
                else
                    age.SetDelay(500);

                age.SetRepeat(0);

                //bad quality
                //string collection
                List<string> strfiles = new List<string>();
                Application.DoEvents();
                for (int i = 1; i <= intDir; i++)
                {
                    //Added by Jaypee
                    if (frm_Status != null)
                        frm_Status.Invoke(frm_Status.d_DelegateSetStatus, new Object[] { "[" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "]Adding frame " + i.ToString() + "." });

                    age.AddFrame(Image.FromFile(GreenScreen.Template.TemplateName + "\\GIF\\Result\\" + strDT.Substring(0, 18) + "\\" + strDT + i.ToString() + ".png"));
                    //strfiles.Add(GreenScreen.Template.TemplateName + "\\GIF\\Result\\" + i.ToString() + ".png");
                }
                age.Finish();
                //Added by Jaypee
                if (frm_Status != null)
                    frm_Status.Invoke(frm_Status.d_DelegateSetStatus, new Object[] { "[" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "]GIF Filename:" + outputFilePath + "->Creation of gif completed." });

                //if (Directory.Exists(GreenScreen.Template.TemplateName + "\\GIF\\Result\\" + strDT.Substring(0, 18)))
                //   Directory.Delete(GreenScreen.Template.TemplateName + "\\GIF\\Result\\" + strDT.Substring(0, 18),true);
                //END Jaypee
}

Problem Details:
When I clicked button (CreateGIFFile()) consecutively (eg. 5 times to process) there is certain file not created. Below is example.

The following are the files should be created in order.
1. 110925687-20100108-Gibbon.gif
2. 110940812-20100108-2009_04_12_4514.JPG.gif - created
3. 111002984-20100108-2009_04_12_4500.JPG.gif -. created
4. 111023609-20100108-2009_04_11_4375.JPG.gif -> not created
5. 111045015-20100108-2009_04_09_3869.JPG.gif -> created and has been processed twice as shown in 20100108_GIF.txt

I attached 2 files so you can see the sequence. In 20100108_GIF.txt, you can see that 111045015-20100108-2009_04_09_3869.JPG. file had been processed twice and 111023609-20100108-2009_04_11_4375.JPG.gif was not created. In FileGIF.txt, you can see the sequence or order where gif files should be created.

Please help me how to resolve it, need to solve this asap.
Thanks

Attachment: Debug.rar

Answers (3)