|
Yes it is, the app listens to the socket on its own thread, so the user can do what they want without the app blocking on the receive (not up to async sockets yet!!). So, that could well be the problem. Haven't come across Control.Invoke, so off to google now.
Thanks to both of you for answering. I will post back with the results.
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Hi
Just been messing with some code - the main application form (which created the second forms based on the 'long' is in thread 1 . I output Thread.CurrentThread.GetHashCode just before the second form is displayed to determine this.
When the socket event is fired, the thread is now Thread 3 . This is where it gets confusing. Calling a method on the main from (created from thread 1 ) from thread 1 , works, and creates the second form a treat. Calling a method from the main form (created from thread 1 ) from thread 3 , fails, and the second form doesn't work.
Is this what you're saying? I should only call methods from the main form, from thread 1 ?
I've looked at Invoke, but not got a clue how to use it with events.
If you can confirm the above I will go away relatively happy and know what the problem is.
Cheers
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Yes that is what I mean. Its generally unsafe to change GUI elements from another thread than they were created in. Like in your case this will normally not result in an immediate exception but some weird behaviour. This even depends on which OS you are using.
The following snippet will demonstrate how to use Invoke with the standard EventHandler signature:
private void OnEvent(object sender, EventArgs e)
{
if (base.InvokeRequired) {
base.Invoke(new EventHandler(OnEvent),
new object[] {sender, e});
}
else
{
}
}
A bit of explanation:
InvokeRequired just checks if the current thread is the one the form was created in or not. Invoke will then transfer the call over the thread boundaries. Thus this function (when called from a different thread) will call itself again within the correct thread. Note that this call may block if the GUI thread is busy and wait till its free. You could also use BeginInvoke. Then the call would not block while the GUI thread is busy and the thread could keep running. The call would than be made the next time the GUI thread is free.
|
|
|
|
|
Blinding answer Robert - thanks.
This fixed the problem a treat, only to highlight a second problem (with similar results). When the 'long' comes in via socket, I fire an event. The main form subscribes to display the second form (discussed above), but so does another form, which the user can enter a long manually to keep the app in sync. Unfortunately, when I update the long on the users form with the long from the socket, an event gets fired which creates the second form. So, when a socket long arrives, two separate evenhandlers attempt to create the second form.....hmmm.
Needless to say, they don't now!!! But I'd have never have got there without the above code anyway.
Many thanks for your answer and your time. Much appreciated.
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
The problem is probably coming from the fact that the socket request is from a remote system and you cannot do a Show() across that boundary remote boundary. ( The exact same behaviour occurs if you setup a remote agent and call a method remotely that would show a form. )
Basically what you have to do is marshal the assembly across the boundaries so that the form is on the local machine and have the caller issue a CreateInstance and call Show() for this to work.
The reason it does not work is that your Show() opens up a message pump on your machine, the empty form opens up on the remote machine, the message pump on the remote machine issues an Activate only there is nothing on the remote machine listening for it on the message pump. Meanwhile your message pump is sitting there getting bored because it is not recieving any messages.
To start research on what it would take to make it work, read about MarshalByRefObject and then think about the impact of shipping Windows Forms all over the network when doing this.
|
|
|
|
|
No, the second thread is on the local machine. The remote machine is a console app, no gui. Just servers a stream of data as and when. Robert's answer about messing about with GUIs across different threads was the problem, but thanks for the info on remoting. I thought C# / .NET would be a walk in the park after 10+ years of C++ / MFC. It's no park! (Or possibly Central Park, NY after 2300 hrs).
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Hi There
This has got to be an easy one... I am coming to ADO.NET from an ADO background, so i appologise if it comes across as totally stupid!
All i want to do is insert a new row into a table and pull back the autonumber primary key assigned to it.
What i don't want to have to do is:
1) Fill a Dataset in order to get a DataTable definition.
2) Use stored procedures.
Anybody know the answer off the top of their head? Guess i really need to buy a good ADO.NET book.
Thanks In Advance
Rich
|
|
|
|
|
You might get a faster answer if you post this question on the ADO.NET board instead of the C# board.
|
|
|
|
|
|
hello, this is my first post here
i want to create a mysql database connection on a remote machine with c#.
well i tried to work with the SqlDataAdapter to create a connection to my www site but it always says no connection possible
after looking for some tutorials i didnt found anything usefull and i hope someone here could help me out
to make it a bit more clearly - how do i connect?
thanks in advance and sry for my bad english
|
|
|
|
|
A more specific error message would be helpful...
Have you installed an OleDb connector for MySQL?
---
b { font-weight: normal; }
|
|
|
|
|
oh well i never did that before :->
first i made a new project, just dragged the SqlDataAdapter in my Design and then the Assistent popped up. i chosed "new connection" and entered the infos in the textboxes below.
the error that appeared was the following: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied (happens when i want to test the connection or pick a database on the server)
thats all what i did
|
|
|
|
|
Have you configured the database for remove access? By default it's only accessible from the same server.
---
b { font-weight: normal; }
|
|
|
|
|
yes its configured but the other reply has got the info i was looking for
(SqlAdapter is only for SQL not MySQL)
thanks anyway for your help
|
|
|
|
|
That is right.
I thought that the SqlConnection could handle any OleDb data source, but as I double checked this (as I often do when faced with contradictory information), I see that the SqlConnection only handles SQL Server, and the passage about OleDb data sources in the reference about SqlConnection is a reference to the OleDbConnection.
---
b { font-weight: normal; }
|
|
|
|
|
|
very very nice thats exactly what i was looking for
thanks a lot
|
|
|
|
|
Hi all, Please advise from you all
I have DataGridView with only one column (use for dynamic menu)
When user press ENTER key, i want to the focus not moving down and show the content of the column
Please advise... thanks
Regards
Sandi Antono
|
|
|
|
|
If you want a dynamic menu, then why use a DataGridView? Why aren't you using the MenuStrip and dynamically constructing the list of MenuItems as needed?
|
|
|
|
|
Cause i use outlook panel too handle that;)
|
|
|
|
|
Good afternoon!
How to define the moment of connection/switching-off usb devices, its type and ID?
Thanks.
|
|
|
|
|
I'm trying to emulate the Magnify tool except it's a bit more limited. I only want to monitor a specific region of the desktop and zoom at a set %.
Here's the code I have so far...
private void GetSnapShot()
{
Bitmap bmp = new Bitmap(273, 273);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(formLocationX, formLocationY, 0, 0, new Size(273, 273));
picDisplay.Image = bmp;
g.Dispose();
bmp = null;
}
I dropped this in a timer's tick event, and it's such a ram slob. It'll use up 4-10mb of ram, then go back down, but it seems so inefficient because it's cycling the ram every 3 seconds or so. The windows magnify tool doesn't use that much ram. I've downloaded a few magnify tools (just to see how they operate) and they don't either.
What can I do to make this better?
The 273 hardcoded values are the size of the picture box. I figured it would be better to hardcode the values rather than get the height/width of the picture box everytime. formLocationX and formLocationY is the area it's monitoring.
I haven't figured out how to zoom in it yet. I set the scale transform and that didn't seem to do anything. I'd much rather get this optimized before worrying about the zoom part though (but if it's a simple task that I am overlooking, feel free to let me know).
-- modified at 13:16 Saturday 17th June, 2006
It just dawned on me that I'm creating a new bitmap everytime. I moved that out of there as well as setting it to null at the end. This stopped the ram from going nuts, I still wouldn't mind any possible ideas on how to make it better though.
|
|
|
|
|
The only big optimisation I'd suggest is to not use a timer if at all possible. For example if you're tracking the mouse then handle a mouse move event (maybe possible in managed code, otherwise the Win32 API will come into play). It all depends on whether the timer is neccessary because you're going to be performing this every 3 seconds or so regardless of whether you actually need to.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
|
|
|
|
|
The ram cycling was occuring every 3 seconds, I'm updating the area every 100 milliseconds.
I'm just looking to zoom into a specific area of the screen (regardless of mouse/keyboard input) and update my picbox with the zoomed in area.
The form won't be open all the time. Overall it's not too bad I guess. After getting rid of the bitmap creation in the function it doesn't use any extra ram. CPU load was 0-2% on a P4 3.0c.
Only problem with using the .NET framework is it doesn't capture everything for some reason. It seems to ignore certain windows for no apparent reason.
|
|
|
|
|
ThisIsMyUserName2 wrote: Only problem with using the .NET framework is it doesn't capture everything for some reason. It seems to ignore certain windows for no apparent reason.
Some programs, like the media player, uses hardware acceleration to display graphics directly to the monitor without drawing it to the screen memory.
---
b { font-weight: normal; }
|
|
|
|