|
C#'s compiled result is a exe in CLR code.
it said required JIT run.
does it mean compile to native code once software is deployed?
or compile each time we used it?
will it be a burden when we develop a fairly big application?
|
|
|
|
|
The JIT compiles each method as it is executed for the first time while running. This is why startup time for a .NET program is so long. You can get rid of the JIT by performing an install time JIT, ngen <assembly> will pre-JIT the code.
There is no guarantee the code won't be JITted again later. However I think it is a safe bet that won't happen since a reason to JIT is when the underlying IL has changed or it has been requested (usually for the above reason).
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Smile your little smile, take some tea with me awhile.
And every day we'll turn another page.
Behind our glass we'll sit and look at our ever-open book,
One brown mouse sitting in a cage."
"One Brown Mouse" from Heavy Horses, Jethro Tull 1978
|
|
|
|
|
Thank you, very helpful.
well, I find it now -- ngen!
|
|
|
|
|
Hi,
If we use Properties in our Class we would need one "local" variable to actually hold the value and one to actually be accessed from the outside...
private string name; // local
public string Name // access outside
{
get
{
return name;
}
set
{
name = value;
}
}
So basically my question is... are there TWO variables or only ONE... Is the public one just for asthetic reasons? If there are two it would be wasting space everytime we use a Property wouldn't it?
Also the "value" parameter - is that always assumed in Properties, cause I don't see any explicit mention of it anywhere?
Thanks.
Mohnish
|
|
|
|
|
I think ONE. ( may be this approach can help us)
As we know , this the way of accessing member variables( state of the class) through methods(get,set) without breaking the client code.
Often memeber variables (State) need to be computed.(ex: get and set to/from DB),then this way of accessing will be useful.
I think this the trade-off.(If we really wasting space)
Check your MSIL using ILDASM.exe( NET FWk/SDK/ bin).
in your example, NAME is property and name is member variable.
Next,
value is implicit parameter for "set" method
CLR reads your program as
set(value)
{
membervariable = value;
}
Thanks,
Anand.
|
|
|
|
|
In your example there is only ONE real member variable: name. Indeed, "Name" just exists just for aesthetic reasons.
Your example doesn't yet show the advantages of using Properties. These arise if you add e.g. bounds-checking code to your get and/or set accessors.
Sito Dekker
|
|
|
|
|
I was wondering if someone can give me a sample code for Upload/Download on FTP.
Is it possible using only TcpClient,NetworkStream,StreamReader or I have to use Socket absolutely ?
Thanks for your help
|
|
|
|
|
I found a sample code here:
http://home.wi.rr.com/skulkarni/FTP/FTPIndex.html
rgrds
Martin
|
|
|
|
|
When a cell inside a datagrid has the focus and the up or down arrow key is pressed the focus moves to the previous or next cell. How can I intercept this event and execute code based on the pressing of the up or down arrow key? The OnKeyUp, OnKeyPress and OnKeyDown are not working as normal in the datagrid. Thanks for your help.
Kyle
|
|
|
|
|
kyledunn wrote:
How can I intercept this event and execute code based on the pressing of the up or down arrow key? The OnKeyUp, OnKeyPress and OnKeyDown are not working as normal in the datagrid.
You need to override the IsInputKey method to tell the datagrid that those keys are to be sent to OnKey* rather than treated specially by the underlying code.
You can only do this if you are creating a class that inherits from DataGrid though.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Smile your little smile, take some tea with me awhile.
And every day we'll turn another page.
Behind our glass we'll sit and look at our ever-open book,
One brown mouse sitting in a cage."
"One Brown Mouse" from Heavy Horses, Jethro Tull 1978
|
|
|
|
|
Thanks James,
What you say about this only being possible if you are creating a class that inherits from DataGrid makes sense since the IsInputKey is a Protected method. Do you know of any code examples available that would help me build this class and add the custom datagrid control to a windows form?
Kyle
|
|
|
|
|
The simplest thing to do is just override the methods that you need to.
public class myArrowKeyDataGrid : DataGrid {
public myArrowKeyDataGrid() : base() { }
protected override bool IsInputKey(Keys key) {
if( key == Keys.Left || key == Keys.Up || key == Keys.Down || key == Keys.Right ) {
return true;
}
else {
return base.IsInputKey(key);
}
}
protected override void OnKeyDown(KeyEventArgs e) {
Keys key = e.KeyData;
if( e.Handled == false && (key == Keys.Left || key == Keys.Up || key == Keys.Down || key == Keys.Right ) ) {
e.Handled = true;
}
base.OnKeyDown(e);
}
} Untested code of course, but thats the premise behind it all
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Smile your little smile, take some tea with me awhile.
And every day we'll turn another page.
Behind our glass we'll sit and look at our ever-open book,
One brown mouse sitting in a cage."
"One Brown Mouse" from Heavy Horses, Jethro Tull 1978
|
|
|
|
|
Thanks James! Everything you wrote made perfect sense and should work. But I still can't get it to work, at least not completely. My data contains 5 text fields and a checkbox. It does work for the cell that has the checkbox but the cells that have the textbox never fire for either the IsInputKey and OnKeyDown events. How it's working for one data type and not another is a mystery to me. If you can think of anything I would appreciate hearing from you. It was very kind of you to help. Thanks.
Kyle
|
|
|
|
|
It'll make it so the Key* events won't fire when an arrow key is pressed but try moving the base.OnKeyDown call so its only called if the key wasn't an arrow key.
It could also be that the TextBox inside the cell is trapping those keys; so you're seeing the behavior of the TextBox and not the datagrid.
James
Sonork ID: 100.11138 - Hasaki
"Smile your little smile, take some tea with me awhile.
And every day we'll turn another page.
Behind our glass we'll sit and look at our ever-open book,
One brown mouse sitting in a cage."
"One Brown Mouse" from Heavy Horses, Jethro Tull 1978
|
|
|
|
|
I know this is dumb question,but I am beginner in C# and do not have any book about it.
I have a text box and a button,when user press this button I want to check if the text boxes are
filled or not,and if the text is empty,change the text of button,I use this but it does not work:
private void Button1_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text==null)
Button1.Text="Hello";
}
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
try this one:
private void Button1_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text.Length == 0)
Button1.Text = "Hello";
}
or set the Enabled-Property of the Button to false at startup
and override the TextChange Property of your TextBox maybe like this:
private void TextBox1_TextChanged(object sender, System.EventArgs e)
{
if(this.TextBox1.Text.Length > 0)
{
this.Button1.Text = "Click me";
this.Button1.Enabled = true;
}
else
{
this.Button1.Text = "Hello";
this.Button1.Enabled = false;
}
}
rgrds
Martin
|
|
|
|
|
Thanx,I check it now
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I think I made amistake about the place of my question,it's in a web form.My button does not enable when I add some text to text box???
Is there any difference between windows form and web application in this case?
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I'm sorry, but I can't help you in this case.
On my new Computer is only Win XP Home Edition installed.
The Home Edition has no IIS, and without IIS i can't create Web-App's.
I planed to Upgrade to Prof. Edition but the 'Update' isn't cheap !!
So I hope that you can get help from another !!
Rgrds
Martin
|
|
|
|
|
Assuming VS.NET wired up your event correctly try changing your code to this:
if(TextBox1.Text == "")
Button1.Text="Hello";
Andy Gaskell, MCSD MCDBA
|
|
|
|
|
Thanks,that works
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Hi,
I am currently trying to dynamically create an instance of a class. My class has a member called XmlReturnData which is derived from XmlDocumentFragment.
Depending on the command which was sent to a client, XmlReturnData can be specialized as - for example - XmlReturnDataLogin.
A class called LoginCommand (derived from XmlCoammd which is derived from XmlDocument) calls its base methods ParseXml() passing the type information of the XmlReturnData - object to create:
Public ParseXml(ByVal returnType As System.Type)
At the end of the method, I am trying to create the appropriate instance of the return object:
Dim args() As Object = { Me, SelectSingleNode(<xpath>) }
m_returnData = Activator.CreateInstance(returnType, args)
Now, I'll get the following exception:
System.Reflection.TargetInvocationEception [...] <------ System.NullReferenceException
So, what can be Null here? The exception is not thrown by the constructor of XmlReturnDataLogin, because I even don't get there.
Kind Regards,
Michael
|
|
|
|
|
Michael Groeger wrote:
m_returnData = Activator.CreateInstance(returnType, args)
The documentation says the exception is thrown when the constructor throws an error; however I have found that it can be other things as well. When I wrote my "extend your .net programs at runtime with interfaces" article I was finding that sometimes I just needed to do a rebuild of all pieces of my project. It seems that the type the program expected was a different version than the one that was actually loaded.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Smile your little smile, take some tea with me awhile.
And every day we'll turn another page.
Behind our glass we'll sit and look at our ever-open book,
One brown mouse sitting in a cage."
"One Brown Mouse" from Heavy Horses, Jethro Tull 1978
|
|
|
|
|
Hi James,
I rebuild the solution, but the problem remains the same. But I found that there was an error in the constructor. I believed that I can break into the constructor from the call to CreateInstance() which was wrong. So I called New() directly and found the mistake.
Thanks for your help!
Michael
|
|
|
|
|
What are the rules for specifying the parameter types for Win API functions using DllImport?
E.g. this thing...
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpDefault, // default string
LPTSTR lpReturnedString, // destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // initialization file name
);
How would I import that? would this be correct...
[DllImport("kernel32.dll")]
static extern int GetPrivateProfileString(string section,
string key,
string def,
string val,
int size,
string file);
|
|
|
|