|
Mark,
... just looking at the footer of your messages ...
Would there be any connection between KIA and "killed in action" ?
SkyWalker
|
|
|
|
|
Mark Nischalke wrote: Having a Dispose method isn't enough by itself. Your class must implment IDisposable.
Well, "must" is not really true. Adding the IDisposable interface to the list of implemented interfaces for the class doesn't really make any difference. It doesn't change the implementation of the class in any way. Using the Dispose method works just fine without the interface, only you can't use the class in a using block as that requires the IDisposable interface.
It's just that the IDisposable interface is intended for this, so if you want to add disposability to a class in a well behaved way, you should implement the IDisposable interface.
Just to be clear.
---
Year happy = new Year(2007);
|
|
|
|
|
Guffa wrote: Well, "must" is not really true...only you can't use the class in a using block as that requires the IDisposable interface.
The post I was responding to makes use of using so in that context, yes it is a must.
If the WriteToDoc class has a dispose method associated with it, you could do the following:
using (WriteToDoc writeToDoc = new WriteToDoc())
{
}
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: The post I was responding to makes use of using so in that context, yes it is a must.
If the WriteToDoc class has a dispose method associated with it, you could do the following:
using (WriteToDoc writeToDoc = new WriteToDoc())
{
}
Correct, but in my original post I was responding to his question to call Dispose, which I thought (possibly erroneously) implied that he had implemented the IDispose interface.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
The recommended way is to implement the IDisposable interface, but it certainly isn't required. Implementing the interface does allow the compiler to understand certain other conveniences, such as the using clause, but it doesn't cause any different compile-time or run-time behavior. It does, however, provide a valuable "clue" to anyone implementing the class that it has certain characteristics and expected behaviors.
For more information on implementing Dispose, check out the following article. It goes in to more detail than the MSDN docs and pulls together the information from some of the people that actually wrote the GC system.
http://www.codeproject.com/useritems/idisposable.asp[^]
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
In MSAccess, RowSource property of ComboBox shows a collection of fields of a query. I know the use of DataSource of ComboBox in C#. But I want to know how to use DataSource in C# to show RowSource-based records like Access because I want to show more fields in ComboBox of C#.
Can we do it ? You will be appreciated.
Many thanks for you 
|
|
|
|
|
i can not doing it ,sorry
eng. rizgar
|
|
|
|
|
Hi all,
I am creating Windows service using C#.net. I wish to put an notification icon in the system tray and need to show some text in the Ballon in the notification icon. Can any one suggest me how to put it???? else give show me some examples to do it.
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
hello!
first, you need two applications:
- one is your service with the main functions and libraries and
- second is an tray application which communicates with your service
for example anti virus programs run services (the main anti virus program) and you can control the behavior of the functions provided by the service over an desktop application - for example in the tray
solidIT.de - under construction
Components for Microsoft .Net
audittrail, objectcomparer, deepcopy and much more ...
|
|
|
|
|
Hi,
Is it a service, or a normal application you are creating?
Also, with Visual Studio 2005, there are controls that make adding notification icons really simple!
Regards,
Cormac Redmond
|
|
|
|
|
Hi,
Thanks all for your kind guidance. I am creating an Windows service in c#.Net 2005.
Thanks once again
Know is Drop, Unknown is Ocean
|
|
|
|
|
There are 5 C# articles on this subject at CP. Type "notify icon" in the search box to display a list.
/ravi
|
|
|
|
|
Basically What I want
In my program, two thread running.
Both thread taking method Name from Array and and executing.
Array containning Method Name List.
Only method name from the Array.
problem is when i m assigning like this i m getting error.
Error "strMN is a Variable but it's used like Method"
strMN getting value from the Array.
strMN is Variable Name.
Code :-
string[] strMName = strMethodName.ToString().Split(' ');
Console.WriteLine("Thread running");
for (int i = 0; i < strMName.Length; i++)
{
string strMN = strMName[i].ToString();
// create a thread for the Incrementer
Thread trdIncrementer = new Thread(new ThreadStart(strMN));
trdIncrementer.Start();
// create a thread for the Decrementer.
Thread trdDecrementer = new Thread(new ThreadStart(strMN));
trdDecrementer.Start();
}
Error "strMN is a Variable but it's used like Method"
Methods:-
///
/// demo function for Incrementer, counts up to 10.
///
public void Incrementer()
{
lock (trdIncrementer )
{
for (int counter = 0; counter < 10; counter++)
{
// assign the incrementer value and display the results
Console.WriteLine("Incrementer: {0}", counter);
}
}
}
///
/// demo function for Decrementer, counts down from 10.
///
public void Decrementer()
{
lock (trdDecrementer)
{
for (int counter = 10; counter >= 0; counter--)
{
// assign the decremented value and display the results
Console.WriteLine("Decrementer: {0}", counter);
}
}
}
help me out .
It's arrgent.
Thanks
|
|
|
|
|
ThreadStart does not take string as an input, it takes method name as an input which is delegate. you can do this if you know the methods at compile time.
ThreadStart(Incrementer);
instead of
ThreadStart(strMN);
-- modified at 4:07 Monday 8th January, 2007
or you can do this
new Thread((ThreadStart)ThreadStart.CreateDelegate(typeof(ThreadStart), typeof(ClassName), strMN));
Regards
Shajeel
|
|
|
|
|
thanks for reply
i am using this
new Thread((ThreadStart)ThreadStart.CreateDelegate(typeof(ThreadStart), typeof(ClassName), strMN));
but iam getting "error to bind the target method"
thanks
|
|
|
|
|
first of all check if class name is correct. second check if the function are static.
Regards
Shajeel
|
|
|
|
|
Thanks
Now code working fine.
could you tell me.
I m storing all method name in Array.
In my application having two Thread.
First thread take method name from array and execute.
second thread take method name from array and execute.
if first thread completed execution then it take 3rd method name from the array Otherwise
if second thread completed execution then it take 3rd method name from array.
like that i want to do.
it's arrgent.
Thanks
|
|
|
|
|
The code that you have provided has only one thread. can you show where are you starting two thread.
The object of threads is to do work simultaneously, you should start all methods simultaneously and if they are dependent on each other then you should add some checking mechanism in your functions so that if they cannot proceed then they should sleep for some times.
you can write like this
for(int i=0; i<count; i++)
{
="" start="" all="" thread.
}
a()
{
="" do="" something
}
b()
{
while(a="" not="" concluded)
{
sleep
}
="" something
}
hope="" this="" help=""
<div="" class="ForumSig">Regards
Shajeel
|
|
|
|
|
I m sending my code .
class ThreadTest
{
static void Main(string[] args)
{
StringBuilder strMethodName = new StringBuilder();
XmlDocument xmlDoc = new XmlDocument();
XmlTextReader readerXml = new XmlTextReader(@"D:\Asif\DotNetProjects\ThreadTest\ThreadTest\XSPMethod.xml");
while (readerXml.Read())
{
switch (readerXml.NodeType)
{
case XmlNodeType.Element: // The node is an element.
//Console.Write("<" + readerXml.Name);
//Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
//Console.WriteLine(readerXml.Value);
strMethodName.Append(readerXml.Value.ToString() + " ");
break;
case XmlNodeType.EndElement: //Display the end of the element.
//Console.Write("");
break;
}
}
ThreadTest t = new ThreadTest();
t.getData(strMethodName);
}
public void getData(StringBuilder strMethodName)
{
string[] strMName = strMethodName.ToString().Split(' ');
Console.WriteLine("Thread running");
for ( int i = 0; i < strMName.Length - 1; i++)
{
string strMN = strMName[i].ToString();
// create a thread for the Incrementer
try
{
Thread trdIncrementer = new Thread((ThreadStart)ThreadStart.CreateDelegate
(typeof(ThreadStart), new ThreadTest(), strMN));
// create a thread for the Decrementer.
Thread trdDecrementer = new Thread((ThreadStart)ThreadStart.CreateDelegate
(typeof(ThreadStart), new ThreadTest(), strMN));
trdIncrementer.Start();
trdDecrementer.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Console.ReadLine();
}
///
/// demo function for Incrementer, counts up to 10.
///
public void Incrementer()
{
lock (this)
{
for (int counter = 0; counter < 10; counter++)
{
// assign the incrementer value and display the results
Console.WriteLine("Incrementer: {0}", counter);
}
}
}
///
/// demo function for Decrementer, counts down from 10.
///
public void Decrementer()
{
lock (this)
{
for (int counter = 10; counter >= 0; counter--)
{
// assign the decremented value and display the results
Console.WriteLine("Decrementer: {0}", counter);
}
}
}
public void Add()
{
lock (this)
{
for (int counter = 0; counter < 10; counter++)
{
// assign the decremented value and display the results
Console.WriteLine("Addition: {0}", counter + 1);
}
}
}
}
|
|
|
|
|
what are the nodes in XML file, it they are Incrementer, Decrementer, and Add
then replace
asif_aslam wrote: for ( int i = 0; i < strMName.Length - 1; i++)
{
string strMN = strMName[i].ToString();
// create a thread for the Incrementer
try
{
Thread trdIncrementer = new Thread((ThreadStart)ThreadStart.CreateDelegate
(typeof(ThreadStart), new ThreadTest(), strMN));
// create a thread for the Decrementer.
Thread trdDecrementer = new Thread((ThreadStart)ThreadStart.CreateDelegate
(typeof(ThreadStart), new ThreadTest(), strMN));
trdIncrementer.Start();
trdDecrementer.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
by
for ( int i = 0; i < strMName.Length - 1; i++)
{
string strMN = strMName[i].ToString();
// create a thread for the Incrementer
try
{
Thread thrd = new Thread((ThreadStart)ThreadStart.CreateDelegate
(typeof(ThreadStart), new ThreadTest(), strMN));
thrd.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
and all methods will run.
Regards
Shajeel
|
|
|
|
|
Thanks for reply.
But can we do same with the help of two thread.
Thanks.
|
|
|
|
|
in your thread there were no two threads, what you were doing was starting all the functions twice and there were six threads. naming thread to increment and decrement does not means you are starting two functions. can you specify what you want as a result exactly.
Regards
Shajeel
|
|
|
|
|
Thanks for reply
I have two thread.
I have more than one method in the array.
I want Two thread should run side by side.
and execute methods.
Suppopse array contains four method name:
1.A
2.B
3.C
4.D
So,
First thread take A method name from the array.
Second thread take B method name from the array.
Once Any of these two thread comleted their task then it has to take next C
method from the array....
Example:-
if suppose 1st thread complete before 2nd thread. it' should take 3rd method name then 2nd thread should not take 3rd method name from the array. it should take 4th method name from the array.
Thanks
|
|
|
|
|
according to this specification i think your code is incorrect. you should do something like that, i am just providing a pseudo code.
static string [] methodlist;
static int currentmethod;
main()
{
}
function X()
{
while(!allmethodscompleted)
{
for calling function from name check out this
<a href = "http://www.codeproject.com/csharp/delegates_and_reflection.asp" rel="nofollow">http:
}
}
Regards
Shajeel
|
|
|
|
|
I want to access child forms save method through mdi toolbar save button.
how can i acesss that method runtime.
because when i call active from's save method it gives me error method or member not define.
Hallo
|
|
|
|