|
i know that in .net it supports both instantiated and static methods to assign in the threadstart delegate, and also i have the knowledge about static and instantiated methods, let me explain the question:
class client
{
public static void thisStaticMethod(object obj)
{
}
public void thisInstantiatedMethod(object obj)
{
}
}
above are the two methods i have and what i want to know what happens when we call the static method in ThreadStart delegate and what happens when we call instantiated method in ThreadStart delegate.
for each thread does it creates a separate instance of the method regardless of whether it is static or instantiated. or what happens behind the screen.
|
|
|
|
|
code never gets instantiated; it exists once, on disk; gets loaded in memory; gets executed in a process, by one thread, or by multiple threads, it does not care. Your cookbook does not care how many cooks are reading it.
Data is different; at the class level, instance data resides in the object; and static data resides in the class (and exists once); all threads can access all such data (and that is exactly why we normally need thread synchronization, we don't want several cooks stirring the same pot of data).
Method local data (whether the method is static or not) resides on the stack of the executing thread (each thread has its own stack), so method local data is always separate.
Conclusion: passing a static or an instance method to a secondary thread, is of the same significance as executing a static or an instance method on the main thread. Most of the time, instance methods (and instance data) is preferred over static ones (static gets often abused); when using multiple threads, this is still true, if not even more so.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
i have the idea about inheritance, but the problem is about the performance when a child class is assigned to a parent class.
please let me explain.
class A is the parent of class B ,an d is the parent of C like wise
A->B->C->D->E->F->G
then i know that when i create an object from class G all the constructors from A to G is called.
Now when i'm assigning an object of G to object of A
A aa = new A();
G gg = new G();
aa = gg;
object "gg" is casted to A type , then is this happens like it happened in creating "gg" all through the hierarchy, or is it just one step from G to A... or is something else happens.. and what about the performance?
|
|
|
|
|
prasadbuddhika wrote: it happened in creating "gg" all through the hierarchy,
No. AFAIK, it is just one step.
Type casting performance - you might want to take a look here.
My signature "sucks" today
modified on Monday, May 24, 2010 11:18 AM
|
|
|
|
|
prasadbuddhika wrote: A->B->C->D->E->F->G
A aa = new A();
G gg = new G();
aa = gg;
nothing gets cast. All the last statement does is forget the existing instance of class G is a highly specialized instance of class A.
If class G represents gray cats, and A represents animals, gg may be the little gray kitten you found yesterday on your doorstep and decided to call Fluffy; still your last statement just says: I'll forget it is gray, I'll forget it is a cat, I just remember it is an animal. But then, it won't meow anymore, as the Meow() method is not in class A, it only exists in F and G.
There is no activity involved.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
thanx for tour explanation
|
|
|
|
|
this is called upcasting.
Reference is to 'A', but type still remains 'G'.
This type of upcast later is very useful in dynamic method dispatch.
|
|
|
|
|
thanx new word for me upcasting
|
|
|
|
|
Hello all!
I'm new to asp.net and i'm trying to bind some XML data to a gridview.
abviously I'm not understanding how to do it properly because that my code doesn't seem to
work...Can anyone could help me please?
this is my xml:
#########################################
<?xml version "1.0" encoding "utf-8"?>
<dictionary>
<item>
<key>
<string> hello world </string>
</key>
<value> <anytype xmlns:q1="http://www.w3.org/2001/XMLSchame" d4p1:type="q1:int"
xmlns:d4p1="http-instance">45</anytype>
</value>
</item>
</dictionary>
and this is my code:
########################################
string path = "D:\\myXmlFile.xml";
DataSet oDs = new DataSet();
oDs.ReadXml(path);
GridView1.DataSource = oDs;
GridView1.DataBind();
thanks
Tom
modified on Saturday, May 22, 2010 8:57 AM
|
|
|
|
|
You would actually find more people answering this question if you would post it in the ASP.Net forum.
My signature "sucks" today
|
|
|
|
|
|
Don't cross post. You have started here and answers have been given here, remove the one you have just posted in the ASP.NET forum before anyone answers there as well.
Read the forum guidelines.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hello, I have an Image I recieve from a stream and I need to save it in the File Format .PBM (Portable Bitmap) because the library I am trying to use only accepts .PBM format. Any ideas How i would do this?
|
|
|
|
|
Spilled wrote: Any ideas How i would do this?
No, however I would start here[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi Experts,
What i am trying to achieve here is a bit tricky. Let me brief on a little background first before going ahead.
I am aware that we can use a enum as a type to a parameter of a method. For example I can do something like this (a very basic example)
namespace Test
{
class DefineEnums
{
public enum MyEnum
{
value1 = 0,
value2 = 1
}
}
class UseEnums
{
public void UseDefinedEnums(DefineEnums.MyEnum _enum)
{
}
public void Test()
{
UseDefinedEnums(DefineEnums.MyEnum.value1);
}
}
}
What i need to do is create a dynamic Enum and use that as type in place of DefineEnums.MyEnum mentioned above.
I tried the following.
1. Used a method which i got from the net to create a dynamic enum from a list of strings. And created a static class which i can use.
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
namespace Test
{
public static class DynamicEnum
{
public static Enum finished;
static List<string> _lst = new List<string>();
static DynamicEnum()
{
_lst.Add("value1");
_lst.Add("value2");
finished = CreateDynamicEnum(_lst);
}
public static Enum CreateDynamicEnum(List<string> _list)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName aName = new AssemblyName("TempAssembly");
AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(
aName, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
EnumBuilder eb = mb.DefineEnum("Elevation", TypeAttributes.Public, typeof(int));
int i = 0;
foreach (string item in _list)
{
eb.DefineLiteral(item, i);
i++;
}
return (Enum)Activator.CreateInstance(eb.CreateType());
}
}
}
2. Tried using the class but i am unable to find the "finished" enum defined above. i.e. I am not able to do the following
public static void TestDynEnum(Test.DynamicEnum.finished _finished)
{
}
I guess the post has become too long but i hope i have made it quite clear.
Please help!
Thanks in advance!
Regards,
Samar
modified on Friday, May 21, 2010 4:43 AM
|
|
|
|
|
Hi Experts,
Any suggestions on this?
Regards,
Samar
|
|
|
|
|
Don't be so damn impatient. We are here voluntarily, this is not a paid support forum.
You can't access the finished enum because it doesn't exit. You cut & pasted the MSDN example which names the enum Elevation.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark,
I am not impatient. I just wanted everyone to know that this thread is active and not dead. Will take care the next time.
I know the enum "finished" does not exists. That is why i tried and separated the declaration and the caller in separate assemblies and gave reference of the declaration assembly in the caller project. This did not work either.
Also I have clearly mentioned in the post that the method is not built by me and that i have "Used a method which i got from the net".
Last words, it would be appreciated if you use a better language than using words like "damn". This is a forum and not your home.
Regards,
Samar
|
|
|
|
|
dashingsidds wrote: I just wanted everyone to know that this thread is active and not dead
Threads don't die. If someone has an answer, or chooses to respond, they will. You adding a response just shows you are impatient and demanding. Again, these forums are not paid support but are voluntary.
dashingsidds wrote: use a better language than using words like "damn"
I'll damn well use damn wherever I please damnit.
Since you are rude and impatient and can't follow the guidelines and etiquette of this site, you're on your own now.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The original poster just posted a reminder and did not specifically demand an answer from "Mark Nischalke" and the language was far more superior than your reply. You could have altogether ignored the post.
|
|
|
|
|
Shameel wrote: posted a reminder
Obvuously you are as ignorant of proper ettique here as the OP was.
Shameel wrote: You could have altogether ignored the post.
As could you have ignored this post as well. So what's your point?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
He also cross-posted -- another no-no.
|
|
|
|
|
I am developing an application using the serial port pin controls when a switch is open or closed, what I do is connect a switch between the pins RTS and CTS (output RTS pin7 to the input CTS Pin8). As a true RTS I have it all the time, pressing the switch changes the state of CTS and through the event PinChanged pick up the change of state and write it down.
The code used is similar to that attached
PrivateSub SerialPort1_PinChanged(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialPinChangedEventArgs) Handles SerialPort1.PinChanged
If e.EventType = IO.Ports.SerialPinChange.CtsChanged Then
class Escribelog(“TZ”)
EndIf
EndSub
But do not get me run this event, even though I look for www, I find that it is advisable not to put too much code in that event, since it must resolve what has very quickly to be available again, which can not be changed controls, but I see no reason why one can not do what I want. But even if ordinary VB in me a working PC.
I read something that perhaps signals the sense that I use have changed, so that as this email on a PDA, when I set the RTS to true, I'm really not one but putting 0, so that pressing connect switch but both RTS to CTS 0, and therefore I do not detect anything, but do not know if this is true or I've misunderstood.
You know how I can find out why it does not work this lucky code.
Thank you very much
|
|
|
|
|
You may have any of the following issues, or combination thereof:
1.
AFAIK you need to open the serial port, and obviously you need to wire an event handler to it, for the handler to become active at all.
2.
connecting RTS to CTS may or may not work, one is an input pin, one is an output pin; if the unconnected input pin has the same logic level as the output pin, then connecting them together won't change a thing. So your scheme will only work for one specific value of the RTS pin. I never can remember the levels, so you would have to look up the details.
3.
almost all asynchronous handlers, and the SerialPort ones for sure, run on ThreadPool threads. Which means they cannot reliably access any GUI Controls. You can (for debugging purposes) include a MessageBox.Show(), that should work; but you can't simply do myLabel.Text="CTS has changed";
This article[^] provides more information about that.
Some remarks:
- a mechanical switch will "bounce", so for throwing the switch once, you are likely to get several "pin changed" events.
- all serial port events get queued; if your event handler takes longer, additional events will get queued and will call your handler with some delay, so you loose the real-time behavior. (That would also be true with you clicking a Button that has a slow handler).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|