|
JoeRip wrote: In fact, the example quite clearly shows the lock being applied in only one place,
That is because the one place is being used by multiple threads. It is being used on ALL (10) sides, in that example.
|
|
|
|
|
Yeah, I figured out my error in thinking. I was so used to using lock (myQueue.SyncRoot) that I had come to think of it as locking the Queue itself, not setting a lock flag on one of the queue's members.
Turns out all I needed to do for my Generic Queues - which I thought didn't have a SyncRoot member, since it didn't show up in VS 2008's Intellisense , was to use
lock (((ICollection)myGenericQueue).SyncRoot)
{
}
It was good to be reminded of what the lock statement was actually doing, though. Thanks!
|
|
|
|
|
No, that doesn't protect the queue. You still have to use a lock around every piece of code that uses the queue.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Agreed, I should have made that clear. I was just explaining why I thought the lock (object) call was actually protecting the object.
And, I was just noting that the lock (((ICollection)myGenericQueue).SyncRoot) statement gives me a nice shared object to lock that can be used by my library code and its callers. I was happy to find I could still do this with Generic Queues, the way I had with... uh, non-generic queues. Specific queues?
|
|
|
|
|
JoeRip wrote: Is this expected?
Yes.
JoeRip wrote: Why is there no collision with the lock?
Because you are not using the lock correctly. The lock doesn't protect the object that you are referring to in any way, the object is only used as an identifier. What the lock does is to prevent another code block locking with the same identifier to be entered (or the same code block to be reentered by another thread).
So, to protect your queue, you need a lock around every piece of code that uses the queue.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
JoeRip wrote: (I can't figure out how to show the angle braces).
Try reading the page you use to post the code into. There is a check box that says something about ignoring HTML or something.
led mike
|
|
|
|
|
I'm following the code here http://www.developerfusion.co.uk/show/4071/1/ to check Verizon email.
On this page the code is started http://www.developerfusion.co.uk/show/4071/7/. I set the server to 'incoming.verizon.net', and my username and password.
When I run it, I get the error "An existing connection was forcibly closed by the remote host".
I'm not sure what this means, or what I'm doing wrong. I checked the code, and it's all entered as exactly as in the article.
Anyone know what this message means?
Everything Makes Sense In Someones Mind
|
|
|
|
|
Just a tip...if you get an error, copy the error message and Google it. There are many chances that you will find the answer there itself without waiting for someone's comment here.
Like this[^]
KMAROIS wrote: I'm not sure what this means, or what I'm doing wrong. I checked the code, and it's all entered as exactly as in the article.
Well, in your case I believe either your username or password is incorrect.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I am not sure what I am missing, pls point me out
public class X{
private MyPage mypage;
public MyPage MainPage { get { return mypage;} set { mypage;= value; } }
ArrayList listedApplication = new ArrayList();
listedApplication.Add("A");
listedApplication.Add("B");
listedApplication.Add("C");
}
I need to assign this Array list to a property
class MyPage
{
private ArrayList applicationList = new ArrayList();
public ArrayList ApplicationList { get { return applicationList; } set { applicationList = value; } }
}
I tried assigning using
MyPage.ApplicationList = listedApplication ;
I get a NullReferenceException, asking me to use new. i tried using
public class X{
private MyPage mypage;
public MyPage MainPage { get { return mypage;} set { mypage;= value; } }
ArrayList listedApplication = new ArrayList();
listedApplication.Add("A");
listedApplication.Add("B");
listedApplication.Add("C");
MyPage.ApplicationList.Add(new ArrayList(listedApplication)) ;
}
but still get the same error, pls help
|
|
|
|
|
There is an incorrect semicolon in your setters. I do not know if that is your problem however.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
maybe you need
public class X{
private MyPage mypage = new MyPage();
... ?
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)
|
|
|
|
|
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
|
|
|
|