Click here to Skip to main content
15,892,005 members
Home / Discussions / C#
   

C#

 
QuestionTCP, channels, sockets sync or async ? Pin
nahumtakum24-Mar-03 23:06
nahumtakum24-Mar-03 23:06 
AnswerRe: TCP, channels, sockets sync or async ? Pin
Anonymous25-Mar-03 7:08
Anonymous25-Mar-03 7:08 
GeneralRe: TCP, channels, sockets sync or async ? Pin
nahumtakum26-Mar-03 7:15
nahumtakum26-Mar-03 7:15 
GeneralCOM Categories in C# Pin
Choppa24-Mar-03 22:12
Choppa24-Mar-03 22:12 
GeneralRe: COM Categories in C# Pin
Stephane Rodriguez.30-Mar-03 7:33
Stephane Rodriguez.30-Mar-03 7:33 
GeneralValidating a xml file Pin
chito24-Mar-03 20:45
chito24-Mar-03 20:45 
GeneralCreating a new From in an eventhandler of a form, the event is invoked by another thread. Pin
krisp24-Mar-03 14:13
krisp24-Mar-03 14:13 
GeneralRe: Creating a new From in an eventhandler of a form, the event is invoked by another thread. Pin
krisp24-Mar-03 23:46
krisp24-Mar-03 23:46 
I have fixed the problem, but im not sure if there is a better way of doing it.

I ended up making a class that displays the ChatBox form I created as ShowDialog(), this seems to noew display the form, as Show() did not work. However, ShowDialog() blocks the thread untill that form is closed. So I have to craete the ChatBox form then pass it to an object that starts a new thread just for it. I dont really like this way because if i have 20 clients im chatting with thats 20 extra threads.

If anyone knows a better way please repsond. Sorry if my first post is a lot to take in, i didnt know how to explain my problem without giving all the background and details.

original problem, trying to be more clear:
a thread invokes an event, and a form (on the main thread) that is listening for the event creates a new form in the event hanlder, but the new form pops up and is "Not Responding".
I see that the new form is actually created in the thread that invokes the event, not the thread that has the form (that has the event handler), I dont really like that, i thought events you fire off and then the form thread would work on the event handler, i think this is why i had a problem (creating a form in a different thread and calling show() if i called showDialog() it works but the other thread blocks). I even tried async events, but even though its not the thread that invoked the event now creating the new form( working on the event handler), but its an anonymous new thread working on the event handler. I dont know how to make it more clear, this does sound confusing reading it back to myself sorry again.

The class to fix the problem, but creates a thread for each new form now:

private class EEChatBoxThread
{
internal EEChatBoxThread( FormEEChatBox chatBox )
{
_chatBox = chatBox;

Thread thread = new Thread( new ThreadStart( ShowChatBox ) );
thread.Name = chatBox.Client;
thread.IsBackground = true;
thread.Priority = ThreadPriority.BelowNormal;
thread.Start();
}

private void ShowChatBox()
{
_chatBox.ShowDialog();
}

private FormEEChatBox _chatBox;
}


Part of MainForm:

public void OnMessageReceived( Object sender, MessageReceivedEventArgs e )
{
FormEEChatBox chatBox = GetChatBox( e.From );
chatBox.MessageRecv( e.From, e.Message, e.Secure );
}

private FormEEChatBox GetChatBox( string with )
{
FormEEChatBox chatBox = ( FormEEChatBox )_chatBoxes[ with ];

// if the chatBox is not already on the screen, make one and display
if( chatBox == null )
{
chatBox = CreateChatBox( new string[] { with } );
}

return chatBox;
}

private FormEEChatBox CreateChatBox( string[] with )
{
FormEEChatBox chatBox = new FormEEChatBox( with, this );
chatBox.Closing += new CancelEventHandler( OnChatBoxClosing );
Monitor.Enter( _chatBoxes );
_chatBoxes.Add( with[ 0 ], chatBox );
Monitor.Exit( _chatBoxes );
// this class is above, just calls ShowDialog() on the chatBox form.
EEChatBoxThread boxThread = new EEChatBoxThread( chatBox );
return chatBox;
}

GeneralRe: Creating a new From in an eventhandler of a form, the event is invoked by another thread. Pin
Chris Jobson25-Mar-03 8:26
Chris Jobson25-Mar-03 8:26 
GeneralRe: Creating a new From in an eventhandler of a form, the event is invoked by another thread. Pin
krisp27-Mar-03 15:14
krisp27-Mar-03 15:14 
GeneralText Box on Desktop Icons Pin
BennyMac24-Mar-03 11:57
BennyMac24-Mar-03 11:57 
GeneralRe: Text Box on Desktop Icons Pin
Don_s25-Mar-03 1:53
Don_s25-Mar-03 1:53 
GeneralCOM Out Of Process Object Equivalent Pin
Anonymous24-Mar-03 11:10
Anonymous24-Mar-03 11:10 
GeneralImporting SWF Pin
zamazula24-Mar-03 10:11
zamazula24-Mar-03 10:11 
Generaldisabling/greying a treeview node Pin
vlusardi24-Mar-03 8:58
vlusardi24-Mar-03 8:58 
GeneralRe: disabling/greying a treeview node Pin
Don_s25-Mar-03 2:57
Don_s25-Mar-03 2:57 
GeneralRe: disabling/greying a treeview node Pin
vlusardi25-Mar-03 6:42
vlusardi25-Mar-03 6:42 
GeneralSecurity Permissions Pin
anirudh24-Mar-03 8:54
anirudh24-Mar-03 8:54 
GeneralRe: Security Permissions Pin
James T. Johnson24-Mar-03 13:19
James T. Johnson24-Mar-03 13:19 
QuestionHow to get Windows Directory with C# Pin
Mmithat24-Mar-03 8:28
Mmithat24-Mar-03 8:28 
AnswerRe: How to get Windows Directory with C# Pin
leppie24-Mar-03 8:35
leppie24-Mar-03 8:35 
GeneralRe: How to get Windows Directory with C# Pin
Mmithat24-Mar-03 9:29
Mmithat24-Mar-03 9:29 
GeneralRe: How to get Windows Directory with C# Pin
leppie24-Mar-03 9:54
leppie24-Mar-03 9:54 
GeneralRe: How to get Windows Directory with C# Pin
Mmithat24-Mar-03 10:03
Mmithat24-Mar-03 10:03 
GeneralRe: How to get Windows Directory with C# Pin
leppie24-Mar-03 9:57
leppie24-Mar-03 9:57 

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.