|
AnilUnni wrote: I tried assigning using
MyPage.ApplicationList = listedApplication ;
I get a NullReferenceException, asking me to use new.
You can't possibly have gotten a NullReferenceException with that code. It's a runtime error, and you can't run the code as it doesn't even compile.
MyPage is a class, and ApplicationList is not a static member of the class, so you can't access it that way.
AnilUnni wrote: MyPage.ApplicationList.Add(new ArrayList(listedApplication)) ;
Using "new ArrayList(listedApplication)" would only create a new ArrayList that is a copy of the first ArrayList, so that doesn't serve any purpose in your case. Adding the ArrayList to the ApplicationList property would create an ArrayList containing an ArrayList, which would work so far, but is surely not what you intended.
The problem is still that you are accessing the ApplicationList property as if it was a static member of the MyPage class.
Unless you are stuck with framework 1.x you should not use the ArrayList class at all. Use a type safe generic list instead, like List<string>.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi
i am working on a project that neede to use multi threading
in a method i use Monitor.Enter(Object) for define a critical area.
now if few thread wants to execute the method , monitor.Enter avoid to run Synchronize the method by all thread at the same time, so few threads will be on wait state.
now my problem is may be user wants to cancell the execution of a thread that is on wait state
how can i kill the thread.???
if i call Thread.CurrentThread..Interrupt() below error appears:
"cannot kill a thread that was in wait state" this is not complete error, this is just shortest of error.
thank you
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
The thread that currently owns the lock should use some mechanism
to indicate a "cancelled" state and then release the lock.
After acquiring a lock, waiting threads should first look at the
cancelled state before proceeding.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
thanks alot mark but whats that mechanism?
i tray alot but cannot find a solution.
please tell me completely
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Add a boolean property to the class perhaps?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You might try to use Monitor.TryEnter . This does not block, however you have to do this in a loop until you finally get the lock. This is called polling/busy waiting and can cost some CPU cycles, but maybe it works better in your case.
while(!Monitor.TryEnter(obj) || !shouldStop)
{
Thread.Sleep(1000);
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I am not sure about the article but even MSDN says that you cannot take full control of a thread. the mostr you can do is to make it wait. I am not sure about article but I remember these things.
Hope it helps.
"If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry
|
|
|
|
|
hi friends?
my question is just the title:
can we retrieve source code of an exe file that compiled with c#.net 2005????
i am working on a project that contain a several code lines that keep few top secure codes.
i affraid that someone can retrieve the code of my application by exe file and got the top secure code lines.
if this subject is possible, please tell me how it is happened? and if it is not impossible please tell me a solution for more safety in my work.
thank you.
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Hi, there are several tools doing this. Personally I prefer Reflector[^]
Mika
|
|
|
|
|
1. google "obfuscator". There are some built in obfuscators in VS 2008, and some commercially available external ones. These make it so tools like "Reflector" can't easily decode your exe
2. google ".net secure strings". .NET provides some ways to store secret values in your code so they can't be decoded at all (theoretically).
|
|
|
|
|
I have a C# class with an event. I have added a handler for this event in a VB.Net windows form. However, within the C# class when I check if any handlers are created it returns null and thus the handler is not called. But I am creating an instance of the class and adding a handler to its event.
Any ideas why the event is now getting wired? Here is some code:
public delegate void ValidityChanged(object sender, EventArgs e);
protected void RaiseEvent(ValidityChanged handler, EventArgs e)
{
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
Here is the handler:
AddHandler Me._selectedSizeRun.Validated, AddressOf SizeRun_Validated
|
|
|
|
|
CodingYoshi wrote: Any ideas why the event is now getting wired?
Since you did not post any code, my guess is you did something wrong. Does that help?
led mike
|
|
|
|
|
The following segment may or may not be syntactically correct, but the overall structure is accurate. Items marked with question marks I am not for certain if they are needed.
include the following in the custom control
public delegate void ValidityChangedHandler(object sender, EventArgs e);
public ?event? ValidityChangedHandler ValidityChanged;
public void OnValidityChanged(object sender, EventArgs e)
{
if(ValidityChanged!=null)
raise event ValidityChanged;
}
when including in parent control:
this.customControl.ValidityChanged+=new ValidityChangedHandler(newMethod);
public void newMethod(object sender, EventArgs e)
{
}
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
I have all that but for some reason when checking for a handler it returns null. Here is the complete code for this portion of the C# class responsible for raising the event:
public delegate void ValidityChanged(object sender, EventArgs e);
public event ValidityChanged Validated;
public event ValidityChanged Invalidated;
Within a method when the object changes I call this:
OnValidated(EventArgs.Empty);
public void OnValidated(EventArgs e)
{
RaiseEvent(Validated, e);
}
protected void RaiseEvent(ValidityChanged handler, EventArgs e)
{
if (handler != null) // this is false although I create a handler below in the vb code
{
handler(this, EventArgs.Empty);
}
}
This is the vb.net code for handling:
Imagine the above C# class's name is SizeRun
Dim run as SizeRun = new SizeRun()
AddHandler run.Validated, AddressOf SizeRun_Validated
Private Sub SizeRun_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs)
' handle the event
End Sub
|
|
|
|
|
I can't see anything wrong with your code.
This (all C#) is basically your code put into a simple console app and it works perfectly!
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SizeRun run = new SizeRun();
run.Validated+= new ValidityChanged(SizeRun_Validated);
run.TestEvent();
Console.ReadKey();
}
static void SizeRun_Validated(object sender, EventArgs e)
{
Console.WriteLine("Validated Event Fired!");
}
}
public delegate void ValidityChanged(object sender, EventArgs e);
public class SizeRun
{
public void TestEvent()
{
OnValidated(EventArgs.Empty);
}
public event ValidityChanged Validated;
public void OnValidated(EventArgs e)
{
RaiseEvent(Validated, e);
}
protected void RaiseEvent(ValidityChanged handler, EventArgs e)
{
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
CodingYoshi wrote: Dim run as SizeRun = new SizeRun()
AddHandler run.Validated, AddressOf SizeRun_Validated
The code you posted does not show the scope of run , nor does it show the OnValidated event being fired. There could be a disconnect between them.
led mike
|
|
|
|
|
Sco
led mike wrote: The code you posted does not show the scope of run
The scope of SizeRun is public else it will give me compilation errors.
led mike wrote: nor does it show the OnValidated event being fired
The method RaiseEvent() fires the event.
|
|
|
|
|
CodingYoshi wrote: The scope of SizeRun is public else it will give me compilation errors.
public is an Access Modifier which determines the Visibility[^] of the variable and is not the same thing as Scope[^]
So we still don't know the Scope of the variable
CodingYoshi wrote: The method RaiseEvent() fires the event.
The method RaiseEvent is called from OnValidated which appears to be an event handler
CodingYoshi wrote: public void OnValidated(EventArgs e)
{
RaiseEvent(Validated, e);
}
The code you posted does not show OnValidated being called or if it is a registered event handler we are not seeing where the event is being fired. Therefore it is possible that your VB code is trigging the event for a different instance of SizeRun class than the one that is used to register the event handler. This is the potential disconnect that I am talking about.
led mike
|
|
|
|
|
I just discovered indexers today (using Reflector and a bit of googling) and found that they solve some problems I had been having with a class. Having just found them, my initial thoughts were "excellent! this solves all of the problems of the world"
So my question is this:
Are indexers common knowledge (and I have been living under a rock until today)
OR
Are indexers obscure things only usually found in the System.whatever?
(The reason I ask is that the project I'm working on seems like a candidate for an article, but when I write it I dont want to patronise people by telling them all about this magic syntax I discovered if everybody already knows)
Thanks,
Chris
[Edit: After a couple of replies it seems that it is common knowledge, however I suspect that people have come from a C++ background - any VB background people care to chip in?]
modified on Monday, August 18, 2008 11:17 AM
|
|
|
|
|
c2423 wrote: Are indexers common knowledge
Yes
c2423 wrote: (and I have been living under a rock until today)
I don't know.
led mike
|
|
|
|
|
Thanks for your input! In conclusion I must just not have been paying attention to the C# books I glossed over...
Chris
|
|
|
|
|
c2423 wrote: Thanks for your input!
No problem. Man I sure missed an opportunity in replying to your other question!
c2423 wrote: (and I have been living under a rock until today)
I don't know, what's your address? I can look it up on Google Street View and tell you!
led mike
|
|
|
|
|
Indexers are nice and commonly used in the .NET framework. If you think they would make sense in your project and simplify the usage of it, then go for indexers.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yes, they simplify my project (in one place I even save an *entire line* of code )
And I know that the framework contains them (for example when reading a SqlDataReader's values)
However, my question was more along the lines of "do people generally know of their existance?"
Anyway, thanks for your input - its good to know that its not an alien concept for people!
Thanks,
Chris
|
|
|
|
|
c2423 wrote:
However, my question was more along the lines of "do people generally know of their existance?"
I think most people use them intuitively when accessing chars in strings, items in lists, values by key in dictionaries and lots of other stuff. Whenever the user knows that there's more data inside a class they either look for a GetXXX -Method or go for indexers without actually knowing that they just use "indexers".
regards
modified 12-Sep-18 21:01pm.
|
|
|
|