473,657 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# threads & dragdrop

2 New Member
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 2232
haplo
2 New Member
Never mind, it seems that moving the pconv function above the [STATHREAD] directive solves the problem.
Jul 28 '08 #2

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

Similar topics

7
5837
by: Kate | last post by:
Hi: I have a form with a picture box and some command buttons to make certain shapes appear in the picture box. The shapes are drawn on blank UserControls added like this: 'at top of form module Dim WithEvents tc As testControl 'button1_click (for example)
0
1310
by: Flack | last post by:
Hello, Is it possible to find out how many methods are listening to a certain event? For example, if a number of methods subscribed to a controls DragDrop event using +=, can I find out how many methods in total are listening to the DragDrop event of the control? If I can't find out the exact number of methods listening to the DragDrop event, can I somehow remove all listeners of that event at once? I tried using m_Control.DragDrop =...
3
3874
by: Goldwind | last post by:
Hi, I"m trying to use drag & drop of text from one text box to another but without suceess. Microsoft presented an example in "101 code samples" BUT in this example the code select and drag all the text in the TextBox, wether the user wants or not. I need to drag only the selected text (changing the example causes it not to work).
3
3786
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the target node in the treeview and auto expand it if applicable... but after a fair bit of head scratching I can't find any easy way to accomplish this. I think what i really need is the equivalent of the HitTest method from the COM version of the...
3
10586
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
2
3471
by: misower | last post by:
var c = document.getElementById("PanelTree"); // PanelTree is a <div> element! var n = document.createElement("div"); n.setAttribute('id', 'nu'); n.setAttribute('style', 'position:absolute;left:0px;top:0px;'); var tmp2 = document.createTextNode('hello'); n.appendChild(tmp2);
1
1668
by: Taptu¶ | last post by:
Hi, Is there any way to use D&D functionality with panel ? Ex. I have 2 panels: panel 1 and panel2 I want to drag panel1 over panel2 and change parent value of panel1 after Drop panel1.parent = panel2; Best regards Taptu¶
1
2305
by: SteveDouglas | last post by:
Hi all, I am currently writing an application in VB.NET that has a lot of controls (treeviews/listviews/labels and so forth) that represent "things" that need to be draggable from place to place, including between controls and windows. In the past when I've implemented Drag and Drop in other projects, I've always passed the item being dragged (for example the listviewitem or the treenode) to the DoDragDrop and then retrieved it in the...
0
1010
by: =?Utf-8?B?Vm9sa2VyUw==?= | last post by:
Hi folks, I've got a prob in using a toolstripbutton as a target of a d&d-operation. I set AllowDrop=true in the formload event, an handle the dragenter event like this one: Private Sub Dragenters(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) If e.Data.GetDataPresent(DataFormats.Text) Then e.Effect = DragDropEffects.All
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.