Hi,
I have a a thread function that calls also to show/load the form. I tried to use showdialog() and it worked. Im also using FormCollection fc = Application.OpenForms objects to close all opened forms, the problem is that, when I used showdialog(), it didn't close at all.
Please help me.
Thanks,
Jaypee
Loading
Nilanka DharmadasaPosted Jan 7, 2010, 6:12 AM
I changed your code. Now it is working.
The reason was a cross thread issue. So you do not need a button. I remeoved the button in form2.
Please do not forget to tick 'Do you like this answer' check box.
jaypee bacolPosted Jan 7, 2010, 10:56 PM
Nilanka DharmadasaPosted Jan 7, 2010, 10:51 PM
Ill llok into this. As this is a separate question, can you post it in a separate thread. Otherwise, this becomes too lengthy and takes time to load. The network i'm using is not a fast one. So please post this as a separate thread.
jaypee bacolPosted Jan 7, 2010, 10:38 PM
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
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,
Jaypee
jaypee bacolPosted Jan 7, 2010, 1:57 AM
It seems that it does not work. Please see attached file. This was the program you wrote. I just added your suggestions here.
Thanks,
Jaypee
Nilanka DharmadasaPosted Jan 6, 2010, 11:51 PM
Don't try to close that form.
Instead try to set a dialog result to the form. You can do that by adding a button to the form.
Let's add a button to the form. If you want you can hide it by button1.visible = false;
Then you set following property of the button.
button1.Modifiers =Public (Or in the designer class make the button a public one instead of private.)
button1.DialogResult = DialogResult.OK;
Now when you want to close the form, you call following.
formobject.button1.PerformClick();
Jaypee, I could not test this. Please try this and let me know if you find any issue.
If you find this useful, please tick 'Do you like this answer' checkbox.