|
Nice find.
From now on, I am going to have this in my windows forms application (of course with proper comments):
public class AppCursor : IDisposable
{
Cursor _currentCursor = null;
bool _setDefault;
public AppCursor(Cursor cursor, bool setDefault)
{
_currentCursor = Cursor.Current;
_setDefault = setDefault;
Cursor.Current = cursor;
}
#region IDisposable Members
public void Dispose()
{
Cursor.Current = (_setDefault) ? Cursors.Default : _currentCursor;
_currentCursor.Dispose();
_currentCursor = null;
}
#endregion
}
|
|
|
|
|
Chris should put that in the advertising. There is an app article for that.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
d@nish wrote: As far as its equivalent is concerned, just see the IL through ILDAsm or reflector and it would make things a bit clear.
I know, but shamefully, I'm IL challenged.
ShamWow
|
|
|
|
|
Wow, everyone got it wrong
Debug or Release?
The debug code (bugs in Reflector corrected by looking at the MSIL)
SomeIDisposableClass CS$3$0000;
bool CS$4$0001;
CS$3$0000 = new SomeIDisposableClass();
Label_0007:
try
{
SomeCode();
goto Label_0021;
}
finally
{
Label_0011:
CS$4$0001 = CS$3$0000 == null;
if (CS$4$0001)
{
goto Label_0020;
}
CS$3$0000.Dispose();
Label_0020:;
}
Label_0021:;
And yes, it is silly. It's storing the result of the null -check
The Release code
SomeIDisposableClass CS$3$0000;
CS$3$0000 = new SomeIDisposableClass();
Label_0006:
try
{
SomeCode();
goto Label_0017;
}
finally
{
Label_000D:
if (CS$3$0000 == null)
{
goto Label_0016;
}
CS$3$0000.Dispose();
Label_0016:;
}
Label_0017:
edit: the rules for goto -within-try are
If the goto statement exits one or more try blocks with associated finally blocks, control is initially transferred to the finally block of the innermost try statement. When and if control reaches the end point of a finally block, control is transferred to the finally block of the next enclosing try statement. This process is repeated until the finally blocks of all intervening try statements have been executed.
|
|
|
|
|
harold aptroot wrote: Wow, everyone got it wrong Debug or Release?The debug code (bugs in Reflector corrected by looking at the MSIL)
Bugs?
+5
I are Troll
|
|
|
|
|
Bugs like this one.. if ((CS$3$0000 == null) != null)
That's not even possible, and the IL for that part is just
L_0011: ldloc.0
L_0012: ldnull
L_0013: ceq
L_0015: stloc.1
L_0016: ldloc.1
L_0017: brtrue.s L_0020
So Mr Reflector just skipped over a load/store and made up a comparison
|
|
|
|
|
That's what I was looking for, thanks!
ShamWow
|
|
|
|
|
Hi everyone,I hope it is not in wrong place to ask, I have some isuues with Compact Frame work datagrid. It does not have much options like windows datagridview have.Can anyone please tell me how do I load data in coloumns and rows like in windows.
thanks
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:25am.
|
|
|
|
|
qwertz321, thanks for your reply. I have seen this many times but I don't know how use them. I know how to deal with regular windows datagrid and I can work with it fine. when it comes to .Net Compact framework I am lost completly because I am making change to the datagrid it does not effect anythig on the datagrid.
forexample, I want to change a particular Cell color or a column or certain row and column I am able to do that.
I am really raelly in trouble with this compact framework.
thanks
|
|
|
|
|
Hello,
I didn't know where to post this question, so I posted it here.
How do I fold all code blocks in every file in all of my project with one command?
I know there is a ctrl+m+o command, which will fold all code blocks in the current file,
but I want something that goes for all the files in my project without having to do ctrl+m+o on each single one of them.
The point is, when I open my files, I want them to be collapsed by default.
Is this the default behavior? Are they all collapsed when I open the project?
Would be nice if there was a possibility to fold all in all of the project.
Thanks
|
|
|
|
|
I'm not sure but I think the VS Power Toys might have this functionality (haven't used it for a while and don't have the link handy - Google is your friend!).
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
nils illegitimus carborundum
|
|
|
|
|
|
Hi all,
well simply after a thread runs, in special situation it(thread) try to refresh a form of my application and an error appeared which says that "you can not change object in other thread ..."
what should i do?
|
|
|
|
|
your description isn't very accurate, however I think this[^] is what you need.
|
|
|
|
|
hi all
i have recently created a new simple control
the problem will came up when we drop it in to the form
because it will set sum unwanted properties in Form1.Designer.cs
i set the Default Value for thees properties
[DefaultValue("89/3/24")]
and also set it in control`s constructor
but the problem still persists
|
|
|
|
|
well,
[defaultValue] is not for setting initialize value for an object, it just change appearance of the property in design time,
[DefaultValue("hello")]
public string txt{get;set}
now in design time when you change the text of this property it would be bold text!
for ur purpose u should define ur property as this:
private string _txt="Hello"; public string txt
{
get
{
return _txt;
}
set
{
_txt=value;
}
}
|
|
|
|
|
i need help on usb drive. when a user inserts a usb drive, auto run starts and diplays some of the options to select from. what i want is to add my applications exe to the list of auto run when usb drive is inserted in usb port, so that i can select my application and do some aftermath. please help. simply i want usb drive to run my application when i insert it into my computer.
|
|
|
|
|
you should pick one forum to ask your question.
|
|
|
|
|
Dear friends
i have developed a windows application the thing i want to do i want to make its demo setup so that i can give it to my clients for a period of time after that application fails to open or reinstallation
i have tried many things but i am fail to make demo
any ideas
thanx in advance
|
|
|
|
|
What part of the process is the actual problem?
|
|
|
|
|
well,
I suggest u to use a hardlock. if so u can store the information of expiration and etc. in it, else u should store those information in a hidden path in a encrypted file
this post is really useful:
Application Trial Maker
good luck
|
|
|
|
|
Greetings,
I grew up learning C and Java, so having just recently taken to C# for a new project, I'm still find my way. Hopefully this isn't a silly question
Basically I wish to build a class that contains configuration info for my application. It needs to hold a port number, a directory/folder name, and 3 arrays: an array of booleans, an array of strings for descriptive names, and an array of integers. I've written get/set methods for the server port number and the array containing the booleans, but Visual Studio 2010 is giving me a compilation error with my get/set methods for the last two arrays. "Type '......' already defines a member called 'this' with the same parameter types". Yet if a try and explicitly set the get/set method for the specific array (without using 'this'), it does not work either.
Here is the code:
namespace Test
{
public class TestConfig
{
private int ServerPort;
private String folderName;
private Boolean[] ChLog = new Boolean[12];
private String[] Label = new String[12];
private int[] CallibrationUnit = new int[12];
public int setServerPort
{
get
{
return ServerPort;
}
set
{
ServerPort = value;
}
}
public Boolean this[int pos]
{
get
{
return ChLog[pos];
}
set
{
ChLog[pos] = value;
}
}
public String this[int pos]
{
get
{
return Label[pos];
}
set
{
Label[pos] = value;
}
}
public int this[int pos]
{
get
{
return CallibrationUnit[pos];
}
set
{
CallibrationUnit[pos] = value;
}
}
}
}
Am I best to avoid using the get/set methods in this case? Or should I use a separate class for each of the arrays I'm trying to set up? (this seems very inefficient to me).
I've searched high and low for an example showing the interection of multiple array variables from within a class, but bizarrely I haven't found anything as complex is what I'm trying to do (and I don't think its that complicated).
Any feedback would be most appreciated.
Benjamin
|
|
|
|
|
Well, the issue here is that "two methods cannot differ in return type only". Here method is indexer (this), but rule is the same. You have three indexers, that only differ in return type, which means, that when you do:
<br />
TestConfig test = new TestConfig();<br />
Console.WriteLine(test[2]);<br />
Compiler will not know, which indexer you want to call, because Console.WriteLine is overriden for string, int and bool. That's why you cannot create indexers like this. You can however create indexer based on other type, for example string. So you can have
<br />
public int this[int pos]<br />
{<br />
}<br />
<br />
public int this[string pos]<br />
{<br />
}<br />
It is possible to do what you want to do, but that would require creation of three additional classes, one for each array you want to store. And indexing would be provided by fields (you have a type StringIndexerTable and field of this type in your TestConfig class).
|
|
|
|
|
Rather than having several arrays running in parallel, you could create a single array holding instances of a new class or struct. Example:
public class Channel {
public Boolean ChLog;
public String Label;
public int CallibrationUnit;
}
public class Test {
private Channel[] channels=new Channel[12];
}
The choice between class and struct is yours; for bigger objects, I would favor class, and also when references come in handy, as in what follows.
Finally, rather than setting an upper limit for the number of channels you can handle, it is often better to use a collection, as in:
public class Test {
private List<Channel> channels=new List<Channel>();
...
channels.Add(new Channel(true, "aha", 3));
Console.WriteLine(channels[3].ToString());
...
}
One advantage of generic lists is they don't need a dimension, as they can grow dynamically.
|
|
|
|