|
As just a simple example:
int max = calculate number;
for (int i=0; i < max; i++)
{
MyClass o = new MyClass();
Thread t = new Thread(new ThreadStart(o.SomeMethod));
t.Start();
} For more information about threading in .NET, see http://msdn.microsoft.com/library/en-us/cpguide/html/cpconthreading.asp[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hey
I'm trying to make an exit button from my main application at the "startup" with the command
this.Close();
but I get
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "FCMain".
and debug stops at
[STAThread]
static void Main()
{
Application.Run(new FCMain());
}
What must i do to exit from my main windows application at "startup"?
Thanks
Thomas
|
|
|
|
|
You cannot call Form.Close while the form is being loaded. If you really need to exit the application before the form is loaded, use Application.Exit . Once the form is loaded, Form.Close is okay to call but won't work (due to bugs in the message pump, apparently) if exceptions were thrown in the UI thread while the form was loading. Instead, call Application.Exit in the event this problem occurs. Otherwise, calling Form.Close on the main application window will close the Form and continue with any statements in the Main entry point.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Application.Exit(); did not work, it didn't exit at all.
My data is like this:
public FCMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
.
.
.
if(bExit)
{
Application.Exit();
}
}
[STAThread]
static void Main()
{
Application.Run(new FCMain());
}
Thanks
Thomas
|
|
|
|
|
You can't call it in the constructor, either. You should read about Windows Forms programming in the .NET Framework SDK. Some previous experience with Win32 and the Windows Management APIs would be helpful with understanding the message pump. In this case, however, the application pump hasn't started. See the line:
Application.Run(new FCMain()); This is actually broken down to something similar to the following when compiled:
FCMain form = new FCMain();
Application.Run(form); Therefore, you should throw an exception from your constructor and handle put a try/catch around the statement above. This will not, however, catch other exceptions unless a SystemException is thrown that causes the main form to crash and returns execution to the entry point.
A better design, however, is to move whatever code causes the need to exit out of the FCMain form's constructor and put it in the entry point (or a method that the entry point calls).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
What I see? the code project is hacked!
|
|
|
|
|
What exactly do you see? You surely aren't referring to the Austalia Day banner, are you? If so, it's not a hack, the admin of this site actually have personallity.
Fear not my insanity, fear the mind it protects.
|
|
|
|
|
Not to mention he's originally from Australia.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
And what about those aweful sexual advertisements? are they the new strategy for making money? If so, I am sorry!
|
|
|
|
|
I'm trying to load some data from a parent form, actually the main Form, of my app into a dialog box using the following:
Config config;
config = ((Form1)this.ParentForm).config;
the ParentForm though is always 'undefined' and a NullReferenceException occurs with the followiing information:
'Object reference not set to an instance of an object'
I'm confused, as I followed the code example in the C# help "Retrieving Information from the Parent Form of a Dialog Box".
What am I doing wrong, how do I manage this?
|
|
|
|
|
When are you trying to do this?
In the constructor? ParentForm has the default value (null) when in the constructor (just like any other variable).
|
|
|
|
|
I'm not doing any of this in the constructor.
A simple case is:
I have 2 forms
Form1 has a public string, myString, initialised with "ABCDEF". It also has a button that when clicked loads Form2:
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
Form2 frm = new Form2();<br />
frm.Show();<br />
}
Form2 has a label on it, in the label's 'Click' event I try to set it's Text with the following:
void label1_Click(object sender, System.EventArgs e)<br />
{<br />
label1.Text = ((Form1)this.ParentForm).myString;<br />
}
This causes the NullReferenceException and when I highlight 'this.ParentForm', it shows as <undefined value="">
Why?
|
|
|
|
|
Ah, I see.
The problem is that when you use Form.Show(), it creates a global form, not a child form.
You either need to set the Parent property manually (which will also put the second form "into" the first form visually) or create a modal form using Form.ShowDialog().
|
|
|
|
|
OK I know about the [Serializable()] and [NonSerialized()] attributes that can be applied to classes and their members. Now lets consider the case were we have version 1.0 of a class:
<br />
[Serializable()]<br />
public class Foo<br />
{<br />
private int m_nBar;<br />
[NonSerialized()]<br />
private System.Drawing.Pen m_pen;<br />
}<br />
and lets assume that in version 2.0 we need to add another member to the class so it looks like this:
<br />
[Serializable()]<br />
public class Foo<br />
{<br />
private int m_nBar;<br />
private int m_nAnotherBar;<br />
[NonSerialized()]<br />
private System.Drawing.Pen m_pen;<br />
}<br />
What happens now when version 2.0 tries to read files written using version 1.0 is that an exception is thrown. What is the most elegant way to handle this? Am I forced to implement ISerializable and do all member serialization myself?
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
To upgrade a serialized document, extend SerializationBinder and override BindToType to bind one version of a Type (passed as a string so you don't have to load older assemblies) to the new Type in your assemblies. See the documentation for the SerializationBinder for more information. You assign this to the IFormatter.Binder property of your formatter, like the SoapFormatter , before deserializing.
On that note, if you're serializing Types for .NET Remoting, you can set the includeVersions to false (either via the .config or the Properties for the formatter sink) so that versions aren't included when serializing an object graph to send across application boundaries.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello!
GDI+ text output makes me sick Sometimes GDI+ writes text with wide s p a c e s between letters, sometimes it writes letters very close together....The same with words...
How can I configure the text drawing style or how can I solve this problems?
My actual code for text output:
<br />
StringFormat Format=new StringFormat();<br />
Format.FormatFlags=<br />
StringFormatFlags.NoWrap | StringFormatFlags.NoFontFallback | <br />
StringFormatFlags.LineLimit | StringFormatFlags.MeasureTrailingSpaces;<br />
<br />
G.DrawString("Some text",Font,Brush,0,0,Format);<br />
<br />
G.DrawString("Some text",Font,Brush,TextRect,Format);<br />
<br />
|
|
|
|
|
Does this all happen with the same font?
|
|
|
|
|
|
Try a different font to determine if the font is causing the problem.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
There was a discussion not long ago about GDI+ squishing characters together at the end of a sentance when NoWrap was used (or a couple other conditions were true). This lead to a topic on MSDN about why it does that and the proper StringFormat to use to eliminate that (StringFormat.GenericTypographic ). Try to use the same flags as that if possible.
As far as spaces appearing between letters, this is fairly odd. I've never seen this when drawing my own strings and have never seen anything documented to even control this. Either the text you're passing has spaces (inproper Unicode string?) or the font you're using has some issues. Try a different one and see.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
This is a known problem in GDI+.
The resolution is to use non-gridfit font hinting or a monospaced font.
You should also use FitBlackBox to prevent the lines from painted at slighty different heights.
Here's how you can check for it (note: i have a fonthint field in my class):
Also AA fonts look very poor in small sizes.
void CheckFontBug(Graphics g)
{
float w = g.MeasureString("w", font, int.MaxValue, sf).Width * 10f;
float l = g.MeasureString("llllllllll", font, int.MaxValue, sf).Width;
fonthint = (System.Math.Abs(w-l) > 0.005f) ?
(fontheight > 14f ? TextRenderingHint.AntiAlias : TextRenderingHint.SingleBitPerPixel) :
TextRenderingHint.SystemDefault;
}
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
The latest programs use only one process for several application instances. An example is Microsoft Word. When you run it for the first time it creates a process and an empty document. When you run the executable for the second time (while first instance still running) then it doesn’t create a new process. It tells somehow to the first process to create just a new empty document. In this manner the program uses lower resources. How to implement it under .NET?
Thanks in advance
|
|
|
|
|
genghis[^] includes an example of how to have a 'single instance' app.
HTH
|
|
|
|
|
Is there some reading on how to organize the initial ideas, for a fairly large software (a graphics software, estimated to take about six months). I feel at loss, not having a computer science background.
|
|
|
|
|
Just a thought: Look for information on the Microsoft Solution Framework: Envisioning phase / Conceptual Design / Logical Design / Physical Design / Developement / Test / Deploy.
MS Exam 70-300 covers this also. (So one of the study guides for that exam could help out - I do NOT recommend the MS Press book for that exam, it is very dry reading and I felt that my major intestine was about to jump into my throat and strangle me in order to prevent me going insane with boredom)
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|