471,120 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

c# threads & dragdrop

2
Hello! I recently tried using threads in my winForms application in c# along with a form containing a drag& drop listbox which resulted in recieving the infamous "DragDrop registration did not succeed." exception. Now, I know from what I've read on the forums that this has something to do with setting the appartment state(or something like that) but I don't know how to do that. Could you please look at the following piece of code and try to guide me through the debbuging process?
Expand|Select|Wrap|Line Numbers
  1. //---This is in the main program--
  2. namespace MediaUL
  3. {
  4.     static class Program
  5.     {
  6.         /// <summary>
  7.         /// The main entry point for the application.
  8.         /// </summary>
  9.         static public string plist;
  10.  
  11.         [STAThread]
  12.  
  13.         static public void pconv()
  14.         {
  15.             string aux, dest,aux2;
  16.             while (true)
  17.                 if (Program.plist != null)
  18.                 {
  19.                     int i = 0;
  20.                     while (Program.plist[Program.plist.Length-i-1] != '.') i++;
  21.                     aux2 = Program.plist.Substring(0, Program.plist.Length - i - 1);
  22.                     i = 0;
  23.                     while (aux2[aux2.Length-i-1] != '\\') i++;
  24.                     dest = aux2.Substring(aux2.Length - i , aux2.Length - 1);
  25.                     aux = "-i \"" + Program.plist + "\" -ar 22050 -ab 32 -f flv -s 320x240 " + dest + "up.flv";
  26.                     Process process = new Process();
  27.                     process.StartInfo.UseShellExecute = false;
  28.                     process.StartInfo.RedirectStandardOutput = true;
  29.                     process.StartInfo.RedirectStandardError = true;
  30.                     process.StartInfo.CreateNoWindow = true;
  31.                     process.StartInfo.FileName = "ffmpeg.exe";
  32.                     process.StartInfo.Arguments = aux;
  33.                     process.Start();
  34.                     while (!process.HasExited) Thread.Sleep(20);
  35.                     process.Dispose();
  36.                     //process = new Process();
  37.                     //for (i = 0; i < Program.plist.Length - 1; i++)
  38.                     //    Program.plist[i] = Program.plist[i + 1];
  39.                     //Program.plist.Intersect("");
  40.  
  41.                 }
  42.                 else Thread.Sleep(20);
  43.         }
  44.  
  45.         static void Main()
  46.         {
  47.             Application.EnableVisualStyles();
  48.             Application.SetCompatibleTextRenderingDefault(false);
  49.             Application.Run(new Form1());
  50.         }
  51.     }
  52. }
  53. //---Relevant code from form1(here is where I start the thread--
  54. private void Form1_Load(object sender, EventArgs e)
  55.         {
  56.             Thread pThread=new Thread(new ThreadStart(Program.pconv));
  57.             pThread.SetApartmentState(ApartmentState.STA);
  58.             pThread.Start();
  59.         }
Many thanks in advance.
Jul 26 '08 #1
1 2086
haplo
2
Never mind, it seems that moving the pconv function above the [STATHREAD] directive solves the problem.
Jul 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Kate | last post: by
3 posts views Thread by Goldwind | last post: by
3 posts views Thread by Gary Dunne | last post: by
3 posts views Thread by VB Programmer | last post: by
1 post views Thread by Taptu¶ | last post: by
reply views Thread by =?Utf-8?B?Vm9sa2VyUw==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.