|
hello;
I have just started using VS2008 C# for windows mobile. I cannot make my label.text continuously display data, I verify the information is being passed but the form is not displaying the information. I tried this simple piece of code and it only displays the last value. please help.
namespace datatran
{
public partial class frmSend : Form
{
int i = 0;
int value;
public frmSend()
{
InitializeComponent();
}
private void btnSend_Click(object sender, EventArgs e)
{
value = Convert.ToInt16(txtBoxSend.Text);
while (i < value)
{
lblCount.Text = i.ToString();
lblCount.Show();
i++;
}
}
}
}
|
|
|
|
|
The reason why it's not working as you expect is that the thread executing your event handler method is also responsible for updating the screen - which it can't while it's executing the event handler method. Once it's done executing the event handler it updates the screen - once, and obviously with the last value that was assigned to the label text. One solution for this would be to employ a Timer (MSDN-Doc[^] / Codeproject Tutorial[^]) which provides you a simple way of changing the label text and updating the screen simultaneously.
I guess this was a desperate measure:
lblCount.Show(); - you don't need to do that each time you update the label text.
|
|
|
|
|
thanks for the idea on the timer, I tried it with the correct time interval but it still did not work. Not sure why.
|
|
|
|
|
The following code only updates the text with the current value of i through each step of the While Loop. So once the While loop is done, the text will of course be only the LAST value.
while (i < value)
{
lblCount.Text = i.ToString();
lblCount.Show();
i++;
}
If you are wanting the textbox to show each step through the While Loop, then try this:
lblCount.Text.Clear();
while (i < value)
{
lblCount.AppendText = i.ToString() + "\r\n";
i++;
}
|
|
|
|
|
thanks, but VS2008 do not support Append
|
|
|
|
|
I'm sorry, I just realized it is a label, not a textbox.
Not sure but this may work:
while (i < value)
{
lblCount.Text = lblCount.Text + i.ToString() + "<br/>";
i++;
}
|
|
|
|
|
|
Thanks all for the help, The answer to my issue is to use a text box instead. This works for me.
while (i < value)
{
textBox1.Text = i.ToString() + "\r\n";
i++;
}
|
|
|
|
|
that's a workaround. not a solution.
Not that, that's a bad thing, but it is important to note the difference.
|
|
|
|
|
It seems like it is looping through all the values and making the label display all of them. It is probably doing this so fast that you only see the last set value.
If you want to see all the values, maybe try lblCount.Text += i.ToString() + " " to display all the values side by side. If you do this, remember to clear out the label before looping.
|
|
|
|
|
thanks, I'm using the text boxes instead of labels.
|
|
|
|
|
Hello folks, I have a problem (as well as with the English language ^ __ ^) with a web service that I have already created and works fine. Now I have to add a header that contains an ssl certificate (.cer) but do not know how to do. Can anyone help? Place below the important part of the code. Thank you all!
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportWithMessageCredential;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
Uri cUri = new Uri("https://Service?wsdl");//reserved data
EndpointAddress ea = new EndpointAddress(cUri);
CVPClient client = new CVPClient(myBinding, ea);
|
|
|
|
|
The method that has the following signature in the code bellow:
“protected virtual void SetProperty<T>(ref T item, T value, [CallerMember] string propertyName = null)”
What type of method is this. The body of the method is in the code in this post.
Thanks,
Truck
protected virtual void SetProperty<T>(ref T item, T value, [CallerMember] string propertyName = null)
{
if(!EqualityComparer<T>.Default.Equals(item, value))
{
item = value
OnNotifyPropertyChanged(propertyName);
}
}
|
|
|
|
|
It's a virtual Generic method, returning no value.
The Generic bit is the <T> - which means that the type of the parameters "T" is defined by the context in which it is called, not when it is defined.
MSDN[^]
You can call it with integers, or strings, or Buttons - it will work with them all.
The virtual bit allows derived classes to override the method to work differently if they wish.
MSDN[^]
If they override it, then the later version will be used when teh method is called. If they don't, this version will.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
i like to know in details and want to visualize how memory is allocated in dotnet program. sorry because i will be asking few question. so please answer point wise in detail.
1) suppose i have class called employee which has data member called empNo, Name and Salary. so i like to know when we will create object of employee then how memory will be allocated ?
2) where memory will be allocated for employee object? in heap or stack?
3) why memory is allocated in heap for object and local variable in stack?
4) i hear some time memory is allocated in heap for local variable but when?
5) where actual data is stored like employee name or salary in heap or stack? if in stack why? why not in heap?
6) i heard that memory is allocated for static class in high frequency heap........what is high frequency heap and how it is different than normal heap?
tbhattacharjee
|
|
|
|
|
I'm not going to answer your questions - but not because I'm nasty: because the questions are wrong!
The distinctions between stack and heap isn't as simple as you might think: and a variable in C# probably isn't what you think it is either - which is at the root of the "wrongness" of your questions.
So: what is a variable?
Simply put, a variable in a method is always allocated on the stack - but it's content may or may not be on the stack, depending on what type of data the variable refers to. If it's a ValueType , then the variable is allocated enough space to hold the whole value: and int is a ValueType , and so is a Point . These are always the same size: you cannot extend the size of a ValueType in any way.
If it's a reference type, then the variable always holds a reference to the actual data, rather than the data itself, and again the variable is a fixed size - only this time it is always either 32 bits or 64 bits depending on the environment your code is executing in. String is a reference type, so is any array.
And that's important: because all reference values are allocated on the Heap: never, ever on the stack.
int i = 6; Integers are ValueTypes , so "i" is on the stack, and is the value of the integer - in this case 6.
Button b = new Button(); Button is a reference type, so the actual data for the new instance is stored on the heap - but "b" is the variable and it is located on the stack, and contains a reference to the actual instance.
But...that doesn't mean that all ValueType instances are on the stack - they aren't: they can be embedded in reference type instances:
public class MyClass
{
public int Value;
}
...
MyClass mc= new MyClass();
mc.Value = 6;
MyClass is a reference type (all classes are reference types, all structs are value types) so the instance data is on the heap, and that includes the value type integer "Value" it contains. "mc" is on the stack and holds a reference to the heap based actual data.
From here it starts to get very, very complicated - there is something called "boxing" to consider as well, where a stack based value is copied to the heap and passed as a reference - far too complicated for a little text box like this one!
Get a c# book - they all explain this with pictures (which helps a lot) and when you've read it have a look at this: Using struct and class - what's that all about?[^] - it explains a bit more about it, but it's not exactly beginner friendly!
[edit]Typos![/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 26-Feb-15 10:11am.
|
|
|
|
|
+5 !
small typo here:
OriginalGriff wrote: copied to the head
|
|
|
|
|
Fixed! (Along with a couple of others... )
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
thanks for your time and answer. you said : that's important: because all reference values are allocated on the Heap: never, ever on the stack.
int i = 6;
Integers are Value types, so "i" is on the stack, and is the value of the integer - in this case 6.
i heard that reference type stored in heap and their corresponding value stored in stack.
you said but this is not very clear MyClass is a reference type (all classes are reference types, all structs are value types) so the instance data is on the heap, and that includes the value type integer "Value" it contains. "mc" is on the stack and holds a reference to the heap based actual data.
is there any book which i can download its pdf version which you read and tell me which chapter discuss memory management related things for c# or any other book which easily help me to understand with picture how and when data stored in heap and stack.
share knowledge if you know what is high frequency heap?
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: is there any book which i can download its pdf version
Do not ask that here again!
Most (if not all) PDF copies of books are in violation of copyright: and we do not support that in any way, shape, or form. Bear in mind that nearly all of the 11 million member here are in the business of getting paid to write something it is very easy to copy and download and you might see part of why! You will not get links to anything illegal or immoral here.
And if you ask again, there is a good chance you may be banned from the site...permanently.
There are several different type of heap in .NET - and it really does get complicated. Seriously, find a book - and buy it - it will be able to go into such things in a lot more detail than we can here.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i am very sorry but it would be helpful if you suggest any book name which help me to understand memory management including heap & stack. looking for help. thanks
tbhattacharjee
|
|
|
|
|
No, since you have already indicated that you are planning on downloading it.
We don't encourage that at all.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: Most (if not all) PDF copies of books are in violation of copyright:
Eh?
There are most definitely books one can download in pdf format for free which do not violate copyright.
Given the sum total of all books ever in print then one might suppose that pdfs of all of those, percentage wise, would be violating copyrights.
However books published in the past 20 years, either popular ones or those with a low sell rate can be found for free, legally, or for sale, again legally, at various places. All in pdf format.
And this includes programming.
One might hypothesize that most, percentage wise, of the good books on programming would in fact require a payment. But would be downloadable.
And if one expands the definition the percentage is going to go up when one considers content from e-books.
|
|
|
|
|
just tell me a books name which discuss in details how memory is allocated when we run our program. thanks
tbhattacharjee
|
|
|
|