|
Hi,
I've developed a .net 2.0 application and am now testing it on different computers. This usually works fine, but on some of the newest computers (core 2 duo laptops from Dell) the program just seems to randomly pop-up an error message saying that my "application has encountered an error and needs to be closed". It doesn't say what kind of error was encountered, and when I drag away the window I can continue to use my program just fine. Any suggestions?
Thanks in advance!
|
|
|
|
|
Just a guess, but I would suspect that your program is multithreaded, and you have a bug accessing some shared structure (e.g. enumerating a collection). Your prorgam keeps running because only a background thread has faulted. There should be a Dr. Watson dump somewhere that might yield some clues...
The flaw shows up on core duos because you have two processors, so simultaneous access by different processors to the same data can happen...
|
|
|
|
|
Yep, it is multithreaded, and the program shows this error when I start using just about all of the thread pool threads available (30+). So this might well be the problem. I've seen the Dr Watson dump but can't find any usefull info in it, could you point me where to look? I can post the dump if you want. Do you think I might be allright if I declare all variables I use as "volatile"?
Thanks for the help so far!
|
|
|
|
|
declareing the variables as volatile will just insure the compiler doesn't optimize their use in loops in a way that might cause strange problems, but it is a good idea for shared variuables (paricularly things like a boolean used to stop one thread from another thread). It won't however prenent things likje one tread incrementing a variable will another thread is doing the same thing (causing, for instance, code to attempt to access beyond the end of an array or collection). For that you nead to use locks to force one thread at a time access. Any collections or arrays that are shared across threads should be protected by locking before making changes, collections should be the synchronized variation and be accessed by locking code.
This article[^] has some good explanations, tips and links to further resources.
|
|
|
|
|
Thanks very very much, I've been trying to figure this out all day. I thought volatile implied putting a lock statement on each variable, that's where I went wrong. Locking the variables manually seems to have solved the issue, thanks again.
|
|
|
|
|
are you using COM in your application.If Yes then check for their Version.it might create some Version problem.
sameer
|
|
|
|
|
No, I'm not using COM, but thanks for the help anyway!
|
|
|
|
|
Hi all,
In other languages we can use the term "parent" for referencing a member of a parent class. C# doesn't have it. In the following code, I post an example of this question.
using System;
namespace NS
{
public class A
{
public static void Main() {
B b = new B();
C c = new C();
c.mc();
}
}
public class B
{
public void mb() {
Console.WriteLine("I'm in class B");
Console.Read();
}
}
public class C
{
public void mc() {
}
}
}
Any idea to do it?
Let the life to be fluent in you. SER
|
|
|
|
|
You have not told the compiler how the classes related to each other.
grivix wrote: // How do you call from here // the method mb() of the class B ?
As you have writtent the code, you don't. Instances of class B and C are not fields of class A so there is no parent/child relationship, the reference to B and C will go out of scope at the end of the static Main() method.
Make the b and c fields of class A . Move the Main() method to its own Program class because it seems out of place in A . (I don't know what A is supposed to do, but I'd say with 99.99% certainty the Main() method does not belong there).
Somewhere in class A you can construct b and c with a reference to this . Classes B and C have a field of type A . In the constructors of B and C you can now store the reference to the parent (A ) as it was passed in to the constructor.
Now, in the method mc() you can reference A (the parent) which can reference B .
I'll leave the question of encapsulation and information hiding as an exercise to you (because you generally shouldn't be using public fields)
Does this help?
|
|
|
|
|
pay attention to everything Colin said, and then remember that in C# the class that is inherited from is called the "base" class, not the "parent" class. The "parent/child" relationship is a design-level description of the flow of data, whereas the actual implementation is not "parent/child" but "base/derived"
...whenever you get the kinks worked out of your logic, remember that when you are wanting to call an appropriate method in the base class, you reference it as "base.Method();"
|
|
|
|
|
Alaric_ wrote: then remember that in C# the class that is inherited from is called the "base" class, not the "parent" class. The "parent/child" relationship is a design-level description of the flow of data, whereas the actual implementation is not "parent/child" but "base/derived"
Actually, I think he was describing an association rather than generalisation. Of couse, I could be wrong because his description was rather hazy. I had actually written half the reply before thinking that he was actually wanting that rather than derivation because of the way he wanted to use class B from class C.
|
|
|
|
|
I'm trying to make work my program with Colin's recommendations, which are very clear.
What i wanted to mean with "parent/child relationship" is the relation of an instance object (child) with the object where the instance is created as a field (parent). This is a different concept of base/derived relationship.
Thanks Alaric
Let the life to be fluent in you. SER
|
|
|
|
|
Your recommendatios are very helpful.
Thanks Colin
Let the life to be fluent in you. SER
|
|
|
|
|
A bit more of a complete answer to the one I gave before. I've repeated my previous description and annotated the source code. The numbers refer to the description below.
Of course, I may be wrong about what you are trying to achieve as from your description I think you are talking about an association parent/child relationship. But you may, as it has been pointed out, be talking about generalisation (classes deriving from base classes).
public class Program
{
public static void Main()
{
A a = new A();
a.DoStuff();
}
}
public class A
{
private B b;
private C c;
public A()
{
this.b = new B(this);
this.c = new C(this);
}
public void DoStuff()
{
c.mc();
}
public void CallMB()
{
this.b.mb();
}
}
public class B
{
private A a;
public B(A a)
{
this.a = a;
}
public void mb()
{
Console.WriteLine("I'm in class B");
Console.Read();
}
}
public class C
{
private A a;
public C(A a)
{
this.a = a;
}
public void mc()
{
this.a.CallMB();
}
}
As you have writtent the code, you don't. Instances of class B and C are not fields of class A so there is no parent/child relationship, the reference to B and C will go out of scope at the end of the static Main() method.
(1) Make the b and c fields of class A.
(2) Move the Main() method to its own Program class because it seems out of place in A. (I don't know what A is supposed to do, but I'd say with 99.99% certainty the Main() method does not belong there).
(3) Somewhere in class A you can construct b and c with a reference to this.
(4) Classes B and C have a field of type A.
(5) In the constructors of B and C you can now store the reference to the parent (A) as it was passed in to the constructor.
(6) Now, in the method mc() you can reference A (the parent) which can reference B.
(7) I'll leave the question of encapsulation and information hiding as an exercise to you (because you generally shouldn't be using public fields)
|
|
|
|
|
This is a very academic answer. I couldn't ask more.
Thanks Colin
|
|
|
|
|
Please anybody can give the XML FAQs for interviews.
Thanks in advance
RR
rr
|
|
|
|
|
FAQ #1: How can I find XML FAQs?
Answer: JFGI ( Just Fracking Google It)
|
|
|
|
|
This is probably a very silly question. I am opening a form(b) from within another form(a) and I am trying to get a variable from form(a) and display its contents in form(b). But I don't know how? I will also be updating the variables in form(a) from form(b)?
I have searched for ideas, but not sure what to search for?
Thanks in advance,
Phil
"Rules are for the obedience of fools and the guidance of wise men"
|
|
|
|
|
Create a public property in form B that sets the variable in form B
from Form B to A is more tricky, or you'll need to pass the object A itself to B or you'll have to create your own event.
thus in form A you'll have something like:
MyForm B = new MyForm();<br />
B.MyProperty = variablefromA;<br />
B.showDialog();
to pass the object A to form B you could pass it through the constructor (MyForm B = new MyForm(this); )
I hope for you this isn't homework...?
V.
Stop smoking so you can: enjoy longer the money you save.
|
|
|
|
|
There are generally two methods used:
1. Send a reference to form A to the constructor of form B, and store the reference in form B. Then you can access form A using the reference.
2. Make the variables in form A static, then you can access them from anywhere by specifying the class name of the form. This of course limits you to never create more than one instance of the form.
---
b { font-weight: normal; }
|
|
|
|
|
Take a look at the following article[^].
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
You beat me to it!
|
|
|
|
|
|
Hi
if I publish a version there is a version number, which increments each publish circle.
I'd like to show this number in an info-box.
But how to get it? (it ist not the Application.ProductVersion. This vesion is the number of the AssemblyInfo.cs)
Thanks
Ariadne
|
|
|
|
|
Hi ariadne,
Is this the version number you are looking for?
Assembly thisAssembly = Assembly.GetExecutingAssembly();
Console.WriteLine(thisAssembly.GetName().Version);
needs using System.Reflection;
HTH
Russ
|
|
|
|