|
|
I generally use the Disposing pattern which has sort of evolved from the IDisposable interface. The pattern when implemented looks like this in code:
public class MyObject : IDisposable { ~MyObject() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private bool _disposed; // indicates if Dispose has been called private void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // TODO: cleanup managed resources in MyObject } // TODO: cleanup unmanaged resources in MyObject _disposed = true; } } }
Once you have this pattern in place your methods can use something like this:
public void SomeOperation() { if (_disposed) return; // TODO: do something }
Of course you're going to want to do something more meaningful then just return -- like throw your own exception or return an error code. It just depends on what you're doing that might call an object that has been disposed.
|
|
|
|
|
Thanks,
1.
But we have to check _disposed before we invoke any methods for an object implementing IDospose. It will make code clutter and not easy to read?
2.
I have checked that the exception is from EndGetContext method of HttpListener class, when will it throw ObjectDisposedException?
regards,
George
|
|
|
|
|
hi
i have two schemas in an Oracle database schema1 and schema2
and they have related tables eg tbl1 in schema1 is related to table2 in schema2
In my C# program i wanna get related data from the two tables display then in a Dataview
how do i do it?
regards paula
|
|
|
|
|
hi
i use wmplayer in my form but when i run with my application got this error
ActiveX control '6bf52a52-394a-11d3-b153-00c04f79faa6' cannot be instantiated because the current thread is not in a single-threaded apartment.
but when i use it in single form i don't have any error.
please tell me how i can use windows media pyer in my application
TNKS
|
|
|
|
|
Windows mediaplayer uses COM, which is single threaded. So as the error message says, you can't use it in a multi threaded application. However it should work fine if you are running it from the same thread in which your form controls are created.
|
|
|
|
|
I m generating a tree through following items
6,2,8,1,4,3,7,9
but having problem implementing the Depth First and Breadth First Search in this tree
How can i implement the Depth First and Breadth First Search.
|
|
|
|
|
sir i want to insert data in two tables using transaction. thee is error occurs at run time . i am giving u a my code please correct it as soon as possible:
con = new OleDbConnection("provider=Microsoft.Jet.Oledb.4.0;data source=E:\\db1.mdb");
com1 = new OleDbCommand("insert into info(user_id,password,name,role,email,contact,address,designation,ques,ans) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "','" + comboBox1.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "')");
com2 = new OleDbCommand("insert into login(user_id,password,role) values('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "')");
com1.Connection = con;
com2.Connection = con;
con.Open();
tr = con.BeginTransaction();
com1.Transaction = tr;
com2.Transaction = tr;
com1.ExecuteNonQuery();
com2.ExecuteNonQuery();
tr.Commit();
MessageBox.Show("inserted");
Signature preview salil_k_singh
|
|
|
|
|
Could you tell what the error is? I'm sure it would help.
My current favourite word is: Bacon!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Post the error and what you are trying and then we will be able to help you.
You should google "SQL Injection" too as your code is vulnerable to attack, you should use parameters in your query.
|
|
|
|
|
I Have an assembly that has been signed with a strong name key, does anybody know if it is possible to get access to the public key in the assymbly from code within the assyembly.
thanks in advance
william T
|
|
|
|
|
The GetPublicKey method of the AssemblyName class.
static void Main(string[] args) { // get the public key AssemblyName asmName = Assembly.GetExecutingAssembly().GetName(); byte[] publicKey = asmName.GetPublicKey(); // convert the public key to a string StringBuilder builder = new StringBuilder(); Array.ForEach(publicKey, keyByte => builder.Append(keyByte)); // output the results Console.WriteLine("Public Key:"); Console.WriteLine(builder.ToString()); }
|
|
|
|
|
Thank you tgrt for your reply.
All the best
William T
|
|
|
|
|
Hi
There do not appear to be any file attributes for the user who last changed a file and the user who created a file, I can get the date and time though. Does anybody know of any way to get this information in C# or if the information is kept at all?
Thanks
|
|
|
|
|
I don't think that information is kept. Or at least I've never seen it.
My current favourite word is: Bacon!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
As far as I know the information is not kept.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I believe you can get the current owner of the file by using IO classes, may be the owner is the one who created it.
|
|
|
|
|
I have trouble with calling a web method dynamically from a combobox which contains the different operations of a web service. My program can work with different web services navigated by a URL that is specified at runtime. The problem is that, the items of the operation's comboBox are not constant and they change if the web service in use changes, so when writing the code, I don't know the web service method which I want to call, and I want it to be retrieved from the combobox at runtime. If we assume that the web reference to the service is called wrg, I don't know how to call the desired method. I want it to be something like this, wrg."comboBox.Text", but this doesn't work...
What should I do?
I'll be thankful with your help
|
|
|
|
|
You could use a switch block and use that to compare the combobox's text:
switch(comboBox.Text)
{
case "Method1":
Method1();
break;
case "Method2":
Method2();
break;
case "Method3":
Method3();
break;
}
It's quite a few more lines than you where expecting of course, but if it works.
My current favourite word is: Bacon!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Thank you so much for your help, but I think there was a little misunderstanding of my question here, the problem is that as I work with different services with different operations(and the service to work with becomes known at runtime, when I receive the WSDL file of it from the user), so when writing the code, I don't know the operation names which may be called to put them in a switch.
|
|
|
|
|
In that case I don't think I can help, sorry. Maybe someone else will know.
My current favourite word is: Bacon!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hi all,
I am using printDocument as my print function (printDocument.print() ). How can i print paper(more than 1 page) with landscap instead of potrait?
any tips are welcome.
regards
cocoonwls
|
|
|
|
|
|
Hi, Gareth
Thanks for your reply.Yes, i got it. But now i am facing another problem that is it won't print more than 2 page for me.Below is my senario:
I am drawing a chart which using e.graphic.drawline() and some other method.The chart which i draw is over the screen (so, i am using scrollbar to allow user to view the full chart).When printing, it just draw a half of the chart for me (only print 1 page).
Any idea or tips to overcome it?
any tips are welcome.
regards
cocoonwls
|
|
|
|
|