|
I'm trying to handle the exception in my project. If the exception raised in same thread, I can handle it by using Try/Catch statement... but I'm not sure how to handle in different thread.....
I have one window application called "WindowsApplication1" and one class library called "ClassLibrary1". I added "ClassLibrary1" to "WindowsApplication1" as a reference.
In WindowApplication1, I have the following code.
delegate void action2();<br />
private void button1_Click(object sender, EventArgs e)<br />
{ <br />
try<br />
{<br />
ClassLibrary1.Class1 obj = new ClassLibrary1.Class1 ();<br />
action2 del = new action2 (obj.foo);<br />
del.BeginInvoke( callback, del);<br />
}<br />
catch ( Exception ex )<br />
{<br />
MessageBox.Show (this,ex.Message);<br />
}<br />
}<br />
private void callback(IAsyncResult a)<br />
{<br />
try<br />
{<br />
action2 a2 = (action2)a.AsyncState;<br />
a2.EndInvoke (a);<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show (this, ex.Message);<br />
}<br />
}<br />
In ClassLibrary1.Class,
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
namespace ClassLibrary1 {<br />
public class Class1 {<br />
public void foo()<br />
{<br />
throw new Exception ("Why!!!");<br />
}<br />
}<br />
}<br />
When I run the application with "Control + F5" (without debugging), I got the messagebox ""Why!!!"" as the exception shown.
but when I run the application with "F5" (with debugging), I don't get the messagebox and Try/Catch statement from Form1 doens't work anymore..
So, How to handle the exception in different thread??
Any idea would be greatly appreciated. Let me know if you are not clear what I meant..
Thanks in advance.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
I need to set the text on various form controls(textbox,label,buttons, etc) across threads.
Right now, I have one method per control. Below is my SetButtonText method.
private delegate void SetButtonTextCallback(System.Windows.Forms.Button tBox, string text);
private void SetButtonText(System.Windows.Forms.Button tBox, string text)
{
if (tBox.InvokeRequired)
{
SetButtonBoxCallback d = new SetButtonTextCallback(SetButtonText);
this.Invoke(d, new object[] { tBox, text });
}
else
{
tBox.Text = text;
}
}
Is it possible to have a generic method that I can pass the control and the text. So the call would look like:
SetControlText(button1,"foo");
or
SetControlText(label3,"bar");
|
|
|
|
|
Just use System.Windows.Forms.Control instead of System.Windows.Forms.Button. Every Control has a Text property.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Wow! So easy easy, I missed it!
Thanks!
|
|
|
|
|
I have written a class that allows our application to manipulate the default printer of a workstation. The code below works perfectly on WinXP but not on Win2000...
ManagementObjectSearcher search = new ManagementObjectSearcher("select deviceid from win32_printer where default = TRUE");
Any suggestions?
|
|
|
|
|
Hi, everyone.
I am doing image alignment which compare the difference between two similiar screenshots and aligned the second image to first one. Now, I am able to solve the difference. For two similiar images, I can get the difference between them. But I am stucked at how to do the alignment. any suggests?
Thank you
|
|
|
|
|
I have a Grid View. Here I have a column "Active". I attached this GridView to objectDataSource. In database this field has true or false value.(1 or 0). But in Grid View I want to show that if this field has value 1 in database the value for this column should show "Yes" but if the value of this field is 0 in data base the The GridView should show "No".
How can I do that.
seema
|
|
|
|
|
Please don't cross post
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hide the Active column on the gridview
Create a new column not bound to a db field.
Use the ItemDataBound event to change the new column based on the contents of the hidden column
|
|
|
|
|
Hello,
I am reading values from an Access Database with an OleDbDataReader. I am using the following command:
myCommand.CommandText =
"SELECT FolderName, SecurityGroupName " +
"FROM tblFolderSecurityTemplateInternal";
I am then putting this data into a dynamic array. Here is my problem. I need a way to have the DataReader output to a multi dimensional array. MyReader only takes one value in the array: Ex: subitems1[j,k] = myReader1[j].ToString(); Ultimately, I want to set subitems[j] = to a new variable called FolderNm and subitems[k] = to a new variable called SecurityGroupNm.
OleDbDataReader myReader1;
myReader1 = myCommand.ExecuteReader();
int nFields1 = myReader1.FieldCount;
while (myReader1.Read())
{
// Create an array of subitems
String[] subitems1 = new String[nFields1];
for (int j = 0; j < nFields1; j++)
{
for (int k = 0; k < 2; k++)
{
subitems1[j, k] = myReader1[j].ToString();
}
}
myReader1.Close(); //Close the reader.
|
|
|
|
|
I may be wrong but, aren't you just duplicating the functionality of a DataSet ? I can't believe the increased overhead would be that dramatic.
|
|
|
|
|
Please don't repost questions this quickly. It's plain rude.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
My application has one MDIparent (say MDIparent.cs) and a tool form (say mainform.cs).
A text box in the mainform.cs takes some strings as input and displays the resulting data on the form. There are thousands of strings that can be entered in the input field that give different data for that particular string.
After entering my first string in the mainform, i open a "new" form in the MDIParent (File-->New) to give me another window of form so that i can calculate data for a different string.
However, when i do that, the application seems to be over-writing the data of the new window onto the first form and vice versa.
My goal is to keep keep the data different for different strings, separate.
Is it a problem with MDIParent or form?
Can anyone give me an idea how can i make sure that the form only subscribes to the proper event on itself alone?
Thanks
|
|
|
|
|
Hello,
I am reading values from an Access Database with an OleDbDataReader. I am using the following command:
myCommand.CommandText =
"SELECT FolderName, SecurityGroupName " +
"FROM tblFolderSecurityTemplateInternal";
I am then putting this data into a dynamic array. Here is my problem. I need a way to have the DataReader output to a multi dimensional array. MyReader only takes one value in the array: Ex: subitems1[j,k] = myReader1[j].ToString(); Ultimately, I want to set subitems[j] = to a new variable called FolderNm and subitems[k] = to a new variable called SecurityGroupNm.
OleDbDataReader myReader1;
myReader1 = myCommand.ExecuteReader();
int nFields1 = myReader1.FieldCount;
while (myReader1.Read())
{
// Create an array of subitems
String[] subitems1 = new String[nFields1];
for (int j = 0; j < nFields1; j++)
{
for (int k = 0; k < 2; k++)
{
subitems1[j, k] = myReader1[j].ToString();
}
}
myReader1.Close(); //Close the reader.
|
|
|
|
|
Hello,
How can I throw event in unmanaged code (cpp) and catch it in managed code (c#) ?
thanks
|
|
|
|
|
Can the C++ code be compiled as C++/CLI? If so, you can define events there like any other managed language.
|
|
|
|
|
you can pass a delegate to unmanaged code, accept it as a function pointer and call it
when you feel like it.
The delegate could then invoke the event using purely managed code.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
With the help of Yesterday`s discussion[^] and this[^] I worked am getting all the type in system.Windows.Forms
Code:
<font>AssemblyName name = new AssemblyName("System.Windows.Forms");
name.CultureInfo = new System.Globalization.CultureInfo("");
name.SetPublicKeyToken(new byte[] {0xb7, 0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89});
name.Version = new Version(2, 0, 0, 0);
Assembly a = Assembly.Load(name);
Type[] types = a.GetTypes();
foreach (Type t in types)
{
if (t.Namespace == "System.Windows.Forms")
listBox1.Items.Add(t.ToString());
}
MessageBox.Show(listBox1.Items.Count.ToString());
</font>
I didnt Understand the meaning of
<br />
name.SetPublicKeyToken(new byte[] {0xb7,0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89});<br />
Can you Explain This
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
When signing assemblies a private and public key are generated by the company distributing the assembly. The company keeps the private key in a secure location. The public key is sent along with the assembly. When the company signs an assembly with the private key, third party users can then use the public key to verify that the assembly has not changed. Basicaly it allows users to detect if someone has tampered with the assembly.
Now, assemblies have four pieces of information to describe their full name. They are Name, Version, Culture, and PublicKeyToken. The PublicKeyToken is the public key which is used to validate that the assembly has not changed.
Now, it is possible to change the assembly and simply sign it will a different private key and update the PublicKeyToken appropriately. But in this case, you application is typically tied to the assembly using the full name (which include the correct public key). So in this case your application won't open the assembly because the public key is not correct.
So, long story short. If you excluded the public key then the assembly would still load, but then someone could drop in a "hacked" version of the assembly and your application would happily load it.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks and regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
I have one more problem
How can I distinguish controls in any namespace / dll
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
You're going to have to explain what you mean by this. What do you mean by "distiguish"?? And in "any namespace"?? What are you trying to do??
|
|
|
|
|
I am creating an article for code project
which is a theme applier for windows forms
we have an xml file with details of theme (Some what like the Concept of CSS)
this will contain 4 projects
1>Control Resizer : it will resize most of the controls at run time (completed)
2>Auto Control Resizer: this will resize all the controls on run time when the form is resized or the screen resolution is changed (completed)
3>UI Applier : this will read the theme from the xml and apply it to the respective forms (Almost completed )
4>UI Maker : this will make that XML file.-> I want to implement the idea that user can select any control at run time (for example a button) he can select that control even if it is custom control, then the control will be shown on the screen, with its property grid. he can modify control at run time and see the effects of the modification on the run time. (partially completed)
now the problem is that I need to get a list of all such controls so that user can select the control and that control can be created at run time.
Thanks and Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
I'm assuming you want the types from a given assembly that derive from System.Windows.Forms.Control. If so, then once you have the assembly loaded you can run the following code:
foreach (Type type in assembly.GetTypes()) {
if (type.IsSubclassOf(typeof(Control))) {
}
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Great
the list is pretty much clear But there are still some extra entries
Like
System.Windows.Forms.Application+MarshalingControl
System.Windows.Forms.Application+ParkingWindow
System.Windows.Forms.AxHost
System.Windows.Forms.UpDownBase
System.Windows.Forms.UpDownBase+UpDownEdit
System.Windows.Forms.UpDownBase+UpDownButtons
System.Windows.Forms.DomainUpDown
System.Windows.Forms.PropertyGrid+SnappableControl
System.Windows.Forms.SendKeys+SKWindow
System.Windows.Forms.StatusStrip+RightToLeftLayoutGrip
System.Windows.Forms.ToolStripComboBox+ToolStripComboBoxControl
System.Windows.Forms.ToolStripOverflow
System.Windows.Forms.ToolStripPanel+FeedbackRectangle+FeedbackDropDown
System.Windows.Forms.ToolStripScrollButton+StickyLabel
System.Windows.Forms.ToolStripTextBox+ToolStripTextBoxControl
System.Windows.Forms.PrintControllerWithStatusDialog+StatusDialog
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|