|
Zilo(svk) wrote: However, it looks that you're not willing to bless my mind with a reason why it doesn't work my way
At this point I don't think I have ever understood what you have said. When I run your code it behaves exactly as I expect it would. My code behaves differently because it is different.
In both cases the usage of the Mutex to verify single instance status works correctly, it is the remainder of the code that is different. Your code correctly identifies that it is a second instance but then continues to launch another instance prior to exiting. My code correctly identifies that it is a second instance and exits directly without launching another instance.
|
|
|
|
|
I disagree
Lets talk in steps :
Assuming:
Mutex is identified by unique name, which only my app knows and uses.
If I dont get Mutex ownership immediately, I don't wait for it (Mutex.WaitOne()), that means I don't have anything to Release.
1. Very first app launch, try to get ownership of Mutex, receives it because Mutex is not owned by any other processes.
2. Do whatever app does.
3. Release Mutex ownership. At this point, there should be no Mutex ownership.
4. Restart app.
5. Starting second app instance. If Mutex was previously released correctly and no other same app's are running (the first one may be still running but Mutex was released), I should receive Mutex ownership same way I received it first time. But for some reason, there is still ownership pending from first Launch sometimes. That's my problem.
6. If has ownership -> Step 2. Else -> Let user know that there cannot be more app instances.
7. If has ownership -> Step 3. Else -> Finishing without releasing ownership (which I don't posses).
8. Restart etc...
|
|
|
|
|
Zilo(svk) wrote: I disagree
With what?
In your app step #4 Restart app, always occurs without regard to the Mutex condition.
In my app step #4 Restart is dependent on the Mutex condition.
|
|
|
|
|
My problem is not that I'm restarting application when mutex is not owned!!! Besides that can never happens in real...
My problem is that I'm not able to (always) own mutex in the second application launch (restart) after it was properly released in first one!!!
That application is not about restarting all the time!!!! But sometimes, when it happens, it may fail for a reason a cannot understand!
|
|
|
|
|
Zilo(svk) wrote: My problem is that I'm not able to (always) own mutex in the second application launch (restart) after it was properly released in first one!!!
As I stated previously I cannot reproduce that behavior. Not with my code or yours.
|
|
|
|
|
hmm..
I can, at least on computer at work. I run exactly that code and it failed.
Let me try at home...
Edit:
I couldn't reproduce that at home either. That's not funny at all....
|
|
|
|
|
If you can't reliably reproduce the functionality if the code, what does that tell you about the quality of your solution?
|
|
|
|
|
u are killing me...
look
I have relatively simple piece of code, that should work perfectly without any problems. It's not something sophisticated. But then, I find out that it's not working so perfectly without any problems, so I try to find out why it doesn't ??? According to all information about Mutex (I read MSDN in the meanwhile) it should work the way I wrote it. So now my question is why it doesn't ? Possibly I might miss some important piece of information... or I don't know why it doesn't work. Maybe my computer at work just got crazy. Anyway, what does that tell about the quality of my solution? I tired of this all...
zilo
|
|
|
|
|
Guys,
Mutex.Close() (in Disposing sequence)
that's it. That's my missing piece of information.
now, I can RIP )
Looks like that on faster CPU's, GC or some other mechanism took care about it(Releasing mutex completely) always before instantiating new app, what my slower CPU at work didn't manage always.
I'm just curious. Did you know it all the time?
zilo
|
|
|
|
|
Nope. I never looked at your code. I read the first part of this thread, and the last part. I never knew you posted any code.
|
|
|
|
|
Hi all,
I have developed a windows application in C#, which is going to display a report and print itt automatically without intimating the user.
The report is displayed in the web browser control using XSL in a windows forms application. I would like to know how to print the report in the landscape format? The user should not be allowed to set the page options like Portrait/landscape.
Please let me know of how this can be achieved from coding
Thanks in Advance.
Thanks and Regards
Madhu
|
|
|
|
|
Hello,
I have a problem when trying to serialize the components(the components are diffrent and they are represented by an interface from that they are derived) of a list using XmlSerializer in C#. The exception message thrown when this line is executed
"XmlSerializer ser = new XmlSerializer(typeof(ISchedule))"
is "Cannot serialize interface BL.ISchedule".
I want to know if is this thing possible and should I avoid the encountered problem.
Thak you!
Lukas
|
|
|
|
|
Hi!
I don't think this is possible.
Think about it: An interface cannot be instantiated. So the XmlSerializer could somehow serialize the public members that are part of the interface, but it doesn't make much sense because there's no way back. If you only have the information concerning the interface, you cannot create an object from this.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi!
I have thought at what you told me before but I want to serialize some classes that are represented by that interface not the interface. I have this some instances of these classes in a list of interface type elements and I don't know how to serialize every element in list without taking in account its particular type only the type it is derived from. Is this thing possible?
Thank you!
Regards,
Lukas
|
|
|
|
|
When serializing, there is always one root object (which is associated with the root node in the xml). I'm assuming you have an object (say MainClass) that has a collection of sub-objects (say in a property called Items). The Items is a collection of objects that implement an interface (say IMyInterface). Is this correct?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi, Tom!
All what you have supposed is true. Help me,please, if you know the solution for this problem.
Thanks,
Lukas
|
|
|
|
|
If you have a set number of classes, then you can specify these classes that can appear in the Items collection, like so:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
public class MainClass {
private List<IMyInterface> items = new List<IMyInterface>();
[XmlArrayItem(typeof(MySubClass1))]
[XmlArrayItem(typeof(MySubClass2))]
[XmlArrayItem(typeof(MySubClass3))]
public List<IMyInterface> Items {
get {
return this.items;
}
set {
this.items = value;
}
}
}
If you have a variable number of items, then instead of using XmlArrayItemAttribute, you can specify the class types using this[^] XmlSerializer constructor. Keep in mind that if you use this constructor, that a new assembly (.dll) is created, saved to disk, and loaded into your application's memory every time you call it (see this[^] for more info).
In either case, you will need to know all the class types that will be in the Items property.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi, Tom!
Thanks a lot!
Lukas
|
|
|
|
|
While using this tutorial, ia have problem in the following code
if (Application.OpenForms.Count > 1)
as error occur that 'System.Windows.Forms.Application' does not contain a definition for 'OpenForms'
Can You please solve my problem
Mandeep
Email: cheers_man2003@yahoo.co.in
|
|
|
|
|
Well - it would seem to me that you have three problems:
1. The error tells you that Application doesn't have a definition for OpenForms.
2. I have no idea where this tutorial is.
3. Questions like this should be asked of the author.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete is correct. But, I can tell you that it sounds like you've stumbled acrossed code written for the .NET Framework 2.0 and above, and you're using .NET 1.1 or below. The Application.OpenForms property didn't show up until .NET 2.0.
|
|
|
|
|
hi
Thanks for reply.
I am using .NET 2003 version. if that event is not available in this version , then please solve my problem by giving me other alternative that I can use in its place.
Mandeep
Email: cheers_man2003@yahoo.co.in
|
|
|
|
|
That's not an event. It's a property that exposes a collection.
There is no equivilent in .NET 1.x. Since all you did was say that this particular line gave you a problem, I can't give you an alternative to anything. You haven't described what the goal of using this code it.
If what you're looking for is something that shows you how to up a Splash screen, then all you need to do is Google for "VB.NET .NET 1.1 Splash Screen".
|
|
|
|
|
Forgive the 'generic' formatting, I don't seem to be able to post 'proper' generic code here.
I have a simple class (see below). I need to have a way to have a SINGLE collection of 'GenericDataElement' objects.
Is this possible? Some of the items may be GenericDataElement<<string>> , while others may be GenericDataElement<<int>>.
public class GenericDataElement<<T>> <br />
{<br />
private string name;<br />
private T value;<br />
<br />
<br />
public string Name<br />
{<br />
get { return name; }<br />
}<br />
<br />
public T Value<br />
{<br />
get { return value; }<br />
}<br />
<br />
public GenericDataElement(string name, T value)<br />
{<br />
this.name = name;<br />
this.value = value;<br />
}<br />
<br />
}
|
|
|
|
|
It isn't possible to have a strongly typed generic list that allows 2 different type parameters, but you can do something like that:
public class GenericDataElement
{
}
public class GenericDataElement<T> : GenericDataElement
{
public GenericDataElement(string name, T value)
{
this.name = name;
this.value = value;
}
private string name;
public string Name
{
get { return name; }
}
private T value;
public T Value
{
get { return value; }
}
}
public class Test
{
List<GenericDataElement> list = new List<GenericDataElement>();
public void TestIt()
{
list.Add(new GenericDataElement<string>("string", "value"));
list.Add(new GenericDataElement<int>("int", 1));
foreach (GenericDataElement gde in list)
{
if (gde is GenericDataElement<int>)
Console.WriteLine("int");
else
Console.WriteLine("string");
}
}
}
But you will have an untyped collection, of course.
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|