|
i,ve developed a simple concurrent server and each client is handled by a new thread, after doing some function in the child thread i update the main form using a delegate, the problem is when an exception is occurred in the child thread even though it is handled my whole application get stuck. what might be the solution for this senario.
and i would like to know , once the child thread is returned is it terminated by itself or do i have to do it manually?
|
|
|
|
|
It terminates itself, I believe. Your best bet is a try/catch to catch any errors you may anticipate and which you want to ignore.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
hi...
U must terminate child thread when an exception occured.....
for more information click below link...
About Threading in c#
|
|
|
|
|
Being a bit of a beginner with .Net and c#, I have a questino on cleaning up resources. In Delphi we would free and object using Object.Free and in the scheme of things all objects had virtual method that would be overridden to clear items within that object. For examlpe i might have an object that contains a bunch of array lists, or memory streams.
I have hear of garbage collection and that C# free's up memory usage automatically,
but i'm not sure how true that is and how deep it goes.
In C# if I have
MyObject class with some arraylists populated with other objects that are created by MyObject
and i use this object in some button click for example, when the click is done will MyObject and all its other objects get released?
Do I need some special routine that the system will automatically call when it goes to dispose of MyObject?
Hope that makes sense...
|
|
|
|
|
dwolver wrote: i'm not sure how true that is and how deep it goes.
It is very true and it is very deep (but only for managed objects)
dwolver wrote: i use this object in some button click for example, when the click is done will MyObject and all its other objects get released?
Yes, eventually. The garbage collector does not run as soon as something is no longer referenced anywhere, it runs when it needs to. And then it will clean up the objects.
dwolver wrote: Do I need some special routine that the system will automatically call when it goes to dispose of MyObject?
Now, you've hit on the word I was going to mention next, "Dispose". If an object uses unmanaged resources then you must implement the IDisposable interface. This requires you to implement a method called Dispose() that is used to clean up the objects that the garbage collector cannot.
So, if you use unmanaged objects or another class that implements the IDisposable interface (like a file stream) then you are responsible for cleaning up the object.
You can call Dispose() manually, but a much neater solution is something like this:
using (FileStream fs = new FileStream(someFileName))
{
}
What happens here is that you tell the compiler that when you exit the using block to call Dispose on the object you created at the start. It doesn't matter how you exit the block. You can call return to exit the method as a whole, an exception can be thrown, whatever. The compiler will ensure that the object's Dispose method is called on your behalf.
|
|
|
|
|
Excellent answer.
I'd just stress that the key sentence is:
So, if you use unmanaged objects or another class that implements the IDisposable interface (like a file stream) then you are responsible for cleaning up the object.
Too often seen replies that say in .Net you can completely disregard memory management issues because of automatic GC.
Regards
David R
|
|
|
|
|
THe fundamentals of .NET are that it manages your memory for you. If an object does not have a Dispose method to call ( and if it does, you should call it ), then you shouldn't have to worry about memory. That's what garbage collection means.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
hi..........
Donn't worry abt memory leaks..
U know one of the important featuere of c#.NET is Its Effective Garbage Collection feature.....
If u want to know more , just click below link....
About Garbage Collection
|
|
|
|
|
helu... can we jus load a windows theme .msstyle and skin our windows form ... is there any support like that....thans...
|
|
|
|
|
People are going to hang you for using text-speak, whilst I would love to hear original answers to your question. Please rephrase it without the SMS-language, it greatly enhances your chances of getting a serious answer.
In case you didn't knew; you don't have to pay per character here
I are troll
|
|
|
|
|
He also multi-posted it seems.
|
|
|
|
|
A multi-sinner..
I are troll
|
|
|
|
|
I was searching thru the web and couldn't realy find a conclusive explanation on how to attach an event to DataGridViewButton.
Since I found the answer to my question I have decided to share it with others...
You can not attach an event to a specific DataGridViewButton. The only way to by pass this block is to use the CellClick event of the DataGridView control. By doing so, keep in mind that this event is automaticly attached to any button on the DataGridView. In order to use this event for a specific button on the row, you will need to check if the object which fired the event has the name of your desired button. Take a look at the example:
if (MyGridView.Rows[e.RowIndex].Cell[e.ColumnIndex].Name == "MyButtonName")
{
}
Also, if you notice, when you click on any row on the first cloumn (the blank one that cause a full row selection) it fires the same event. The problem is that it sends a column index of -1 which can not retrive a coulmn name. This cause an expectaion error. In order to fix it use this example:
if (
e.ColumnIndex != -1 &&
MyGridView.Rows[e.RowIndex].Cell[e.ColumnIndex].Name == "MyButtonName")
{
}
Make sure the first condition is the "e.ColumnIndex != -1".
Hope I could help anyone with this information.
|
|
|
|
|
Im tring to edit a project that was original created in China and some of the chinese is causing errors in the compiler, we have 1 laptop that is setup to translate, but I cant figure out how to set my computer to do this also. Ive tried installing the East Asian language pack thats included in windows, but that didnt work. Anyone happen to know how to do this?
|
|
|
|
|
Hello there, i'm trying to connect to a contactless card reader via USB.
I'm using the SetupDiGetClassDevs -> SetupDiEnumDeviceInterfaces -> SetupDiGetDeviceInterfaceDetail -> CreateFile-> DeviceIoControl
But unfortuantly my method fails. I cant get the device handle from CreateFile , because the USB divice name that i get from the SetupDiGetDeviceInterfaceDetail cannot be directly used for the CreateFile.
My USB device name is \\\\?\\usb#vid_072f&pid_8003#5&1903a12b&0&1#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
But i guess the string has to be formatted is some kind of way so it can be used in the CreateFile method/ Please help !
|
|
|
|
|
|
Thank you for your answer but that doesnt help me at all
|
|
|
|
|
I'm working with a windows foem application. I have a dataset that was returned from a webservice. The third column ("Permanent") contains a bool. When i bind the data to a datagridview, that coulmn shows up as a series of checked checkboxes (since all the rows happened to have "true" for that value). What I want to do is modify the dataset, before binding it to the grid, to display the word "Permanent" if the bool is true and "Temporary" is the bool is false. I've gotten the code the point where I recognise whether it's true or false, but, because the column expects a bool, I can't put in the appropriate string. Any suggestions?
<br />
private void btnGetAccounts_Click(object sender, EventArgs e)<br />
{<br />
BindingSource bs = new BindingSource();<br />
dsAccounts = new DataSet();<br />
dsAccounts = myAccount.List(nSessionID, out nError, out sErrorMsg);<br />
if (dsAccounts != null && dsAccounts.Tables.Count > 0)<br />
{ <br />
for (int i = 0; i < 10; i++)<br />
{<br />
if ((bool)dsAccounts.Tables[0].Rows[i][2] == true)<br />
{<br />
dsAccounts.Tables[0].Rows[i][2] = "Permanent";<br />
}<br />
}<br />
<br />
bs.DataSource = dsAccounts;<br />
bs.DataMember = dsAccounts.Tables[0].TableName;<br />
dgvAccounts.DataSource = bs;<br />
}<br />
}<br />
The error I get is: "String was not recognised as valid Boolean. Couldn't store "Permanent" in Permanent column. Expected type is Boolean."
|
|
|
|
|
|
Close but no cigar. Or maybe it -is- a cigar, and I just don't know it.
The link does describe what I want to do, but I have a problems with it.
The example uses ASP and not windows forms. Thus it has a datagrid not a datagridview (datagrid is not available in windows form apps). Also the event "RowDataBound" is not an event that is available for datagridview. I could hand type it from scratch, but how would I make it fire at the right time?
|
|
|
|
|
Whoops, didn't notice it was ASP.net
The cell formatting event should do basically the same thing for c# if you set the datagridview column type to string
Ex.
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if ((bool)e.Value)
e.Value = "Permanent";
else
e.Value = "Temporary";
}
|
|
|
|
|
No joy. I got a "specified cast is not available" on the "if ((bool)e.Value)" line. However, I have an acceptable work around (though it may make thing slow when i get a lot of data flowing). I created a class "Account" with a class member variable for each of the four fields in my dataset, including the "Permanent" (where in my class Permanent is a string. So, once I get my data set, I create an arraylist of Accounts, looping through the dataset until it's done, copying each field of the dataset one at a time, modifying the contents as desired. Then I bind the arraylist to my datagridview.
Not as elegant as using an event, but may be better in the long term, as I have to deal with these accounts.
Here's the Account class:
using System;
using System.Collections.Generic;
using System.Text;
namespace TestMTAccounts
{
public class Account
{
string m_AccountID;
public string AccountID
{
get { return m_AccountID; }
set { m_AccountID = value; }
}
string m_Name;
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
string m_Permanent;
public string Permanent
{
get { return m_Permanent; }
set { m_Permanent = value; }
}
string m_TermDate;
public string TermDate
{
get { return m_TermDate; }
set { m_TermDate = value; }
}
}
}
And here's the new method:
private void btnGetAccounts_Click(object sender, EventArgs e)
{
dsAccounts = new DataSet();
dsAccounts = myAccount.List(nSessionID, out nError, out sErrorMsg);
if (dsAccounts != null && dsAccounts.Tables.Count > 0)
{
ArrayList alAccounts = new ArrayList();
Account acctMyAcct;
for (int i = 0; i < 10; i++)
{
acctMyAcct = new Account();
acctMyAcct.AccountID = (string)dsAccounts.Tables[0].Rows[i][0];
acctMyAcct.Name = (string)dsAccounts.Tables[0].Rows[i][1];
if ((bool)dsAccounts.Tables[0].Rows[i][2] == true)
{
acctMyAcct.Permanent = "Permanent";
acctMyAcct.TermDate = "N/A";
}
else
{
acctMyAcct.Permanent = "Temporary";
acctMyAcct.TermDate = (string)dsAccounts.Tables[0].Rows[i][3];
}
alAccounts.Add(acctMyAcct);
}
this.dgvAccounts.DataSource = alAccounts;
}
}
}
I appreciate the suggestions, though!!
|
|
|
|
|
Hi
I want to print the data of the DataGridView by splitting the columns. That is each column of the DataGridView should split and should be displayed in individual tables on a form or Print view. For example the Print view of a DataGridView should look like this
# # #
# # #
# # #
Note: Here each # represents the table of a column of the table.
Here the number of rows and columns will change, so preferably the number of column's tables should change dynamically.
If any one know the solution Please kindly send me.
Thanking you
|
|
|
|
|
I would recommend using CrystalReports. But in order to help you more you need to try and draw us a clearer picture of what is your plan...
If you can, post a print screen of your desired final result and we'll see how it goes from there.
|
|
|
|
|
Thank you for your reply
If we have a table like this
Customer Details:
Customer Name E-Mail Phone Job Date
John John@gmail.com 34567 Code 31-01-09
Mary Mary@hotmail.com 67890 Design 01-02-09
Swetha Swetha@live.com 87654 Testing 02-02-09
then the Print View of this should look like this.
Customer Name E-mail
John John@gmail.com
Mary Mary@hotmail.com
Swetha Swetha@live.com
Phone Job
34567 Code
69890 Design
87654 Testing
Dates
31-01-09
01-02-09
02-02-09
i.e., each column of the Customaer Details Table should be displayed in a separate individual tables.
ex:if the table have 10 columns then in Printview 10 invividual tables for these columns chould be displayed.
How to display it dynamically in a windows form.Note that the number of columns and rows will vary dynamically
|
|
|
|