Hi, I'm using the code from this article to detect if another instance of my program is running and raise the other instance if it is, closing down the seccond instance of my program. However, I would like to parse the command line parameters given to the seccond instance towards the first instance of my program, prefferably by invoking some kind of method on it. Is there any way of doing this?
sjembek
Posts
-
Cross-instance method invoking -
Microsecond timers/delaysA bit late, but just wanna thank you for the tip, this works excellent!
-
Microsecond timers/delaysHi, I'm testing a piece of hardware that receives network traffic and want to see exactly at what frequency it gets overburdened by the load of traffic. To do this I wrote a simple program that sends packets at a set interval. My problem is the following: The hardware doesn't break up at intervals of 1 millisecconds, so I need higher resolution delays or timers in my program (somewhere in the order of 50 microsecconds or so) than the timers I've been using (Threading.Timer or Forms.Timer). I found an article on the net saying this is possible with C++, but I can't find any info on the subject in c#. Can anyone help? Thanks in advance for any help I might get...
-
Catching minimize eventI mean having it stick to a specific side of its parent, just like controls can. Actually, this is easier than I though. Just set an mdi parent and set the dock property for you form to try it out.
-
Catching minimize eventAh ok, thanks. That worked. Now we're at it, would anyone happen to know how to make my mdi client window dock to its parent? Thanks again, cheers.
-
Catching minimize eventHi, What event should I catch if I want to replace the minimize button code. I've tried catching the "Sizechanged" event but this fires every time a window is opened or resized, I only want to catch the event caused by the minimize button. I want to use this to create an application specific "taskbar" for all of my MDI client windows. Thanks in advance for any suggestions made!
-
Problem with timer event fireingIf you're stopping another timer, why not just change its interval to the interval you had in mind for the third timer and hook up the right event listener to it?
-
Ports.SerialPort freezesOk, I already found the problem, for some strange reason the port needs to be reconstructed:
port = new SerialPort(port.PortName, port.Baudrate);
Weird...
-
Problem with timer event fireingAre you using the System.Windows.Forms.Timer or the System.Threading.Timer? If you're using the tick event it looks like you're using the windows forms timer. If so, make sure you're using it in a class that inherits from
Form
, otherwise it won't work. TheThreading.Timer
is a better option in that case, you can set the interval and a callback function in its constructor. -
Ports.SerialPort freezesHi I'm using the SerialPort class (.net 2.0) for rs232 communications. Unfortunately, an it freezes up my program when I try to set a parameter for it after it's been opened. First I initialize the port:
SerialPort port = new SerialPort(comname, 19200);
port.Open();
port.ReceivedBytesThreshold = 63;
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);Then I do some communications stuff. So far so good. The freeze occurs when I try to use the port for some other process.
if (port.IsOpen)
{
port.DiscardInBuffer(); // will freeze here
port.DiscardOutBuffer(); // here
port.Close(); // here
}port.ReceivedBytesThreshold = 1; // or here
port.Open();Any of the commented line freeze up my program as if in a blocking state, and the code doesn't throw an exception of any kind, it just freezes each and any thread currently running. Does anyone have any clues what's happening here?
-
Unsubscribing all event listenersHi, Thanks for the suggestion, someone has offered me the memento pattern before, and next time I'm implementing a feature like this I'll be sure to use it. Unfortunately I found out a bit late about this in order to use it for the current project: Should I want to convert my project to use this pattern would mean I'd have to change about 1500 base datatypes to start using it, I'm afraid I don't have the time or spirit to do so. For now I found an ugly hack around the problem: I serialize the class and store it to a memorystream, then inmedialtely deserialize it and add it to my
Collection
of "undo" objects. Since the event is marked as non-serializable it gets initialized to null as soon as I deserialize it. It's a bit ugly and I still don't see why I can't just setevent myEvent = null
. But this performs quite well actually. Cheers and thanks for the help! -- modified at 10:10 Friday 25th August, 2006 -
Unsubscribing all event listenersThx for the answer, wasn't expecting anyone to reply anymore. I've thought about that solution too, but I think there should be a more elegant way to fix the issue. The reason I want to do this: the class concerned here contains some data that's shown and can be modified in dozens of places in my application. I've created a sort of "undo" function that saves a copy of the object to memory so that the user can "rollback" on his actions. These copies should contain only data, and shoudn't even try to fire any events. While debugging I found out that some references were left to my cloned objects, meaning the data in these clones is getting modified just as my "foreground" data. What's more, the number of cloned objects in memory could eventually be many thousands, so the performance hit for even for simply checking a flag each time isn't something I want. Since manually disconnecting my eventlisteners is so sensitive to my own errors (code intensive) I'd like to be sure all eventlisteners get disconnected from the event. I'd expect the event itself to contain a list of references to all listeners. As I said before: How else could you check an event for
null
. Suggestions are still welcome of course :) -
Unsubscribing all event listenersIs there any way to unsubscribe all event listeners for a certain event?
public delegate void myHandler(object Sender);
public event myHandler somethingChanged;private void onSomethingChanged()
{
if(somethingChanged != null) somethingChanged(this);
}What I would like to do is something like
somethingChanged = null
. Why isn't this allowed if I can actually checksomethingChanged
for null?somethingChanged -= someFunction
is not an option, what I want issomethingChanged -= allListeners
. Can anyone help me out here? -
Copy an instanceWorks perfectly... Thank you.
-
Copy an instanceThis works, thx :)
-
Copy an instanceLooks interesting, I'll try this out...
-
Copy an instanceActually it is
Serializable
since it can be stored to disk too. I just had a go with this but I haven't serialized to memory before and for some reason I'm getting aSystem.Runtime.Serialization.SerializationException: End of Stream encountered before parsing was completed.
The code looks like this.Collection myOutputCollection = new Collection();
BinaryFormatter bFormatter = new BinaryFormatter();
MemoryStream mStream = new MemoryStream();
OutputData myOutput;bFormatter.Serialize(mStream, myOutput);
deserializedOutput = (OutputData)bFormatter.Deserialize(mStream);
myOutputCollection.add(deserializedOutput);
mStream.Close();
I'm serializing and deserializing the object, then adding it to a collection, since I'm still using it from the collection once it's added (it's not like I don't need it anymore).
-
Copy an instanceI see the use of the pattern, but it seems this will only work for a single member that defines the state, while I meant the state of the object itself and all of its members... I'm afraid this won't work, but thanks for the info.
-
Copy an instanceIs it possible to make an exact copy of an instance of an object (not its reference)? This is what I'd like to achieve: 1 make a copy of an instance at a certain moment to save the state it's in 2 modify the original for a bit 3 replace the original object with the saved one later on This way I'd like to be able to "recall" the state my object was in at the moment I made a copy. Is this possible without manually constructing a new object of this type and copying all of it's members?
-
UnauthorizedAccessExceptionNope.