Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
AnswerRe: Object reference not set to an instance of an object? Pin
Member 428013630-Dec-08 2:09
Member 428013630-Dec-08 2:09 
Questionhow can i import another projects/language .exe file into my project to run in C# Pin
D V kirankumar30-Dec-08 1:48
D V kirankumar30-Dec-08 1:48 
AnswerRe: how can i import another projects/language .exe file into my project to run in C# Pin
Christian Graus30-Dec-08 4:26
protectorChristian Graus30-Dec-08 4:26 
GeneralRe: how can i import another projects/language .exe file into my project to run in C# Pin
D V kirankumar30-Dec-08 23:00
D V kirankumar30-Dec-08 23:00 
QuestionSubclassing Help Pin
JimWWhite30-Dec-08 1:22
JimWWhite30-Dec-08 1:22 
AnswerRe: Subclassing Help Pin
Brij30-Dec-08 2:14
mentorBrij30-Dec-08 2:14 
GeneralRe: Subclassing Help Pin
JimWWhite31-Dec-08 1:24
JimWWhite31-Dec-08 1:24 
QuestionThread marshalling problem Pin
Member 428013630-Dec-08 0:47
Member 428013630-Dec-08 0:47 
Hi I have a problem that I cannot figure.

I have stripped the code down to a few lines that show the issue below.

Basically I have a worker thread that obtains an object and then makes a method call on that object that works fine. But when I return the object to the parent thread, from the parent thread the method call on that object fails. This is the problem. I have a guess about why it fails, but am not sure how to resolve it.

It may be that I need to do something extra to marshal the object back to the parent thread (as you can see I am not doing anything at all right now)

If the worker thread isn't marked as STAThread then the method call in the worker thread fails too, indicating that there is COM stuff going on in the background. I guess the problem is that the underlying object returned creates a COM object in the worker thread's apartment. When the object is invoked from the parent thread the method fails because the underlying COM object doesn't belong to the apartment of the parent thread. Does that sound at all correct?

Is there any way to resolve this?

class Program
{
    static AutomationElement searchResult;

        [STAThread]
        static void ThreadFunc()
        {
            searchResult = FindObject();
            searchResult.FindAllChildren(); //Method PASSES!
        }

        [STAThread]
        static void Main(string[] args)
        {
            Thread t = new Thread(new ThreadStart(ThreadFunc));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
            MyObject obj = searchResult;
            obj.FindAllChildren(); //Method FAILS!
        }
    }
}

AnswerRe: Thread marshalling problem Pin
Natza Mitzi30-Dec-08 4:33
Natza Mitzi30-Dec-08 4:33 
GeneralRe: Thread marshalling problem Pin
Member 428013630-Dec-08 5:14
Member 428013630-Dec-08 5:14 
QuestionResource file issue Pin
George_George30-Dec-08 0:24
George_George30-Dec-08 0:24 
AnswerRe: Resource file issue Pin
Natza Mitzi30-Dec-08 5:02
Natza Mitzi30-Dec-08 5:02 
GeneralRe: Resource file issue Pin
George_George30-Dec-08 18:09
George_George30-Dec-08 18:09 
QuestionPrint Reports Pin
zeeShan anSari30-Dec-08 0:09
zeeShan anSari30-Dec-08 0:09 
AnswerRe: Print Reports Pin
Paddy Boyd30-Dec-08 0:44
Paddy Boyd30-Dec-08 0:44 
GeneralRe: Print Reports Pin
zeeShan anSari30-Dec-08 0:54
zeeShan anSari30-Dec-08 0:54 
GeneralRe: Print Reports Pin
Paddy Boyd30-Dec-08 1:00
Paddy Boyd30-Dec-08 1:00 
QuestionMaking Control of Form Pin
Xmen Real 29-Dec-08 23:25
professional Xmen Real 29-Dec-08 23:25 
AnswerRe: Making Control of Form Pin
rah_sin29-Dec-08 23:31
professionalrah_sin29-Dec-08 23:31 
AnswerRe: Making Control of Form Pin
Tom Deketelaere29-Dec-08 23:45
professionalTom Deketelaere29-Dec-08 23:45 
GeneralRe: Making Control of Form [modified] Pin
Xmen Real 30-Dec-08 1:43
professional Xmen Real 30-Dec-08 1:43 
AnswerRe: Making Control of Form Pin
Abdul Rahman Hamidy30-Dec-08 9:41
Abdul Rahman Hamidy30-Dec-08 9:41 
Questionhow do we daclare an array in a struct? Pin
dec8229-Dec-08 23:21
dec8229-Dec-08 23:21 
AnswerRe: how do we daclare an array in a struct? Pin
N a v a n e e t h29-Dec-08 23:27
N a v a n e e t h29-Dec-08 23:27 
GeneralRe: how do we daclare an array in a struct? Pin
dec8230-Dec-08 0:01
dec8230-Dec-08 0:01 

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.