473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

window handle already exists

Hi,

I've begun programming C# a few days ago, and now I'm experiencing a problem
I really don't understand.

I've create a new Windows Application project in Visual Studio .NET and my
Main method looks like this:

public static void Main( string[] args )
{
ProgramFrame pf = new ProgramFrame();
LogHandler.getInstance().registerLog( new ScreenLog( pf.LogArea ) );
LogHandler.getInstance().registerLog( new OutputLog() );
new Thread( new ThreadStart( Server.Server.getInstance().run ) ).Start();
Application.Run( pf );
}

pf is a System.Windows.Forms.Form object containing a RichTextBox (LogArea)

When the server thread starts it uses the singleton instance of LogHandler
to write som text to the RichTextBox and I get the following error:

An unhandled exception of type System.InvalidOperationException occured in
system.windows.forms.dll

Additional information: Window handle already exists.

Can anyone please explain to me, why this isn't possible, and what can I do
to make it work?

Best regards,

René
Nov 16 '05 #1
8 8523
Hi rene,
I don't quite understand what you wanna do, a login screen?

The problem may be that you are using of.LogArea before calling
Application.Run , I'm not an expert in WIN32 though.

Also what the worker thread does?

I would change the LogHandler calls to the ProgramFrame OnLoad handler

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"René Iversen" <riversen@SLET_DETTE_riversen.dk> wrote in message
news:ce**********@news.cybercity.dk...
Hi,

I've begun programming C# a few days ago, and now I'm experiencing a problem I really don't understand.

I've create a new Windows Application project in Visual Studio .NET and my
Main method looks like this:

public static void Main( string[] args )
{
ProgramFrame pf = new ProgramFrame();
LogHandler.getInstance().registerLog( new ScreenLog( pf.LogArea ) );
LogHandler.getInstance().registerLog( new OutputLog() );
new Thread( new ThreadStart( Server.Server.getInstance().run ) ).Start(); Application.Run( pf );
}

pf is a System.Windows.Forms.Form object containing a RichTextBox (LogArea)
When the server thread starts it uses the singleton instance of LogHandler
to write som text to the RichTextBox and I get the following error:

An unhandled exception of type System.InvalidOperationException occured in
system.windows.forms.dll

Additional information: Window handle already exists.

Can anyone please explain to me, why this isn't possible, and what can I do to make it work?

Best regards,

René

Nov 16 '05 #2
I've found out if I insert Thread.Sleep( 100 ) in the ScreenLog it appears
to be working... but why? Is this really necessary?

/René
Nov 16 '05 #3
René Iversen <riversen@SLET_DETTE_riversen.dk> wrote:
I've begun programming C# a few days ago, and now I'm experiencing a problem
I really don't understand.

I've create a new Windows Application project in Visual Studio .NET and my
Main method looks like this:

public static void Main( string[] args )
{
ProgramFrame pf = new ProgramFrame();
LogHandler.getInstance().registerLog( new ScreenLog( pf.LogArea ) );
LogHandler.getInstance().registerLog( new OutputLog() );
new Thread( new ThreadStart( Server.Server.getInstance().run ) ).Start();
Application.Run( pf );
}

pf is a System.Windows.Forms.Form object containing a RichTextBox (LogArea)

When the server thread starts it uses the singleton instance of LogHandler
to write som text to the RichTextBox and I get the following error:

An unhandled exception of type System.InvalidOperationException occured in
system.windows.forms.dll

Additional information: Window handle already exists.

Can anyone please explain to me, why this isn't possible, and what
can I do to make it work?


What is your other thread doing? If it's trying to do anything with the
UI, that may well be the cause of the problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Hi rene,

What are you trying to do?

The thread you create may be the problem, maybe you are trying to access
the UI from there.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"René Iversen" <riversen@SLET_DETTE_riversen.dk> wrote in message
news:ce**********@news.cybercity.dk...
I've found out if I insert Thread.Sleep( 100 ) in the ScreenLog it appears
to be working... but why? Is this really necessary?

/René

Nov 16 '05 #5
Hi Rene,

First of all it is not correct and most of the time leads to unpredictable
effects if you try use a control from code that runs in a thread not created
the control. In your case the thread that run that server will probably try
to write in the richeditbox, which has been created in the main UI thread.

It is really hard to say what is wrong unless you don't provide a simple
working application that we can play with in order to find the problem. So
if you can post such a code we could help you more. Otherwise we can only
guess
--

Stoitcho Goutsev (100) [C# MVP]
"René Iversen" <riversen@SLET_DETTE_riversen.dk> wrote in message
news:ce**********@news.cybercity.dk...
Hi,

I've begun programming C# a few days ago, and now I'm experiencing a problem I really don't understand.

I've create a new Windows Application project in Visual Studio .NET and my
Main method looks like this:

public static void Main( string[] args )
{
ProgramFrame pf = new ProgramFrame();
LogHandler.getInstance().registerLog( new ScreenLog( pf.LogArea ) );
LogHandler.getInstance().registerLog( new OutputLog() );
new Thread( new ThreadStart( Server.Server.getInstance().run ) ).Start(); Application.Run( pf );
}

pf is a System.Windows.Forms.Form object containing a RichTextBox (LogArea)
When the server thread starts it uses the singleton instance of LogHandler
to write som text to the RichTextBox and I get the following error:

An unhandled exception of type System.InvalidOperationException occured in
system.windows.forms.dll

Additional information: Window handle already exists.

Can anyone please explain to me, why this isn't possible, and what can I do to make it work?

Best regards,

René

Nov 16 '05 #6

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> skrev
i en meddelelse news:OO**************@TK2MSFTNGP12.phx.gbl...
Hi rene,
I don't quite understand what you wanna do, a login screen?

No, it's a server that runs in it's own thread :: new Thread( new
ThreadStart( Server.Server.getInstance().run ) ).Start();

When a new connection is made to the listening socket it uses the singleton
instance of LogHandler to log the activity ( and thereafter when there are
any activity). When the loghandler runs through the list of registered logs
which in this case is a ScreenLog and and OutputLog (just
system.console.writeline(...) ) the ScreenLog will append some text to the
LogArea which is a RichTextBox. Hope this helps you to understand my problem
better.
The problem may be that you are using of.LogArea before calling
Application.Run , I'm not an expert in WIN32 though.

Maybe, I'm no experts also... at all! :-). But I don't think so. the
constructor on the RichTextBox has been called, so it should be OK in my
opinion.
Also what the worker thread does?

See above...
I would change the LogHandler calls to the ProgramFrame OnLoad handler

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nov 16 '05 #7

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> skrev
i en meddelelse news:%2******************@TK2MSFTNGP10.phx.gbl...
Hi rene,

What are you trying to do?

The thread you create may be the problem, maybe you are trying to access
the UI from there.


Yes, it is accessing the UI... the RichTextBox (LogArea.AppendText)
Nov 16 '05 #8
This was the problem:

http://www.devx.com/dotnet/Article/11358/0/page/3

I used a delegate and the invoke method on the RichTextBox ... problem
solved!

Thanks for you help!
Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Display Name | last post by:
the customer I'm developing a site for uses a canned form-parsing page that allows her to have an email subscription opt-in page add emails to a list she can manage using a link that you point your...
3
by: John Bokma | last post by:
I have two windows in a frame. I want to be able that each can open a pop up window and that the handle to that window can be stored somewhere, so that each can talk to the pop up. is it...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
8
by: Mészáros Tamás | last post by:
Hi all, how can I set an app's main window to visible from an other application? My problem is, that I know only the handle of the other app's main process, because the application's main window...
1
by: spamproof2005 | last post by:
I have the following code: Dim BrowserLauncher As New ProcessStartInfo BrowserLauncher.FileName = URL BrowserLauncher.CreateNoWindow = False BrowserLauncher.UseShellExecute = True...
13
by: Seth Grimes | last post by:
Hello all, I want to open a window when a user leaves my site. I set up a function called by onUnload. To skip the window.open if the user hasn't left my site, I set a variable in my links and...
7
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses...
2
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some...
16
by: CreativeMind | last post by:
hi, i have a page calendar.aspx which returns selected date i.e window.returnValue=selectedDate; window.close(); it works fine with IE but not for Firefox. i tried...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.