|
It looks like you've somehow got confused and stored a weak reference to a weak reference. I'd double check your Add() code, and make sure you're only storing a weak reference to a string and not a weakreference to a weakreference to a string.
Simon
|
|
|
|
|
i need a full list of naming conventions for all controls in c#, including workflow activities!
|
|
|
|
|
|
Member 2069064 wrote: i need a full list of naming conventions for all controls in c#, including workflow activities!
Dont type in bold, there is nothing to emphasize here.
Well, naming conventions vary from Organization/Groups. The primary goal of having them is to make the code look as it was written by one developer i.e. readable and easy to understand.
Though you can find general conventions here[^].
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
|
Yessir, of course sir, I will look into it right away sir!
..wait, I don't work for you, do I?
|
|
|
|
|
I need a shed load of wonga, but I don't expect to get an answer to it here.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I am writing a class that wraps and helps me deal with calls to an external c++ library from C#. My class is used in a webservice environment, so must be sensitive to the multi-threaded nature of web requests, however I dont think the c++ library was ever written with this in mind so I must be careful how I call it.
To simpify things the C++ library has a few methods I must call
Init - must be called only once, the first time my class is used
SendData - used to start a communication
ReceiveEvent - must be called on a timer with a short interval, used for receiving events back from the external library (and I use it to raise events in my class)
ShutDown - must be called once before the application exits
Now this structure I think lends itself to a Singleton which takes care of the Init/Shutdown, and a factory method to create my instance of a "Call". Feel free to suggest another approach if you think im wrong there.
The problem im having is in ensuring that "Init" has been called before any other thread manages to call SendData. eg
Thread1 calls SingletonObject.Instance.CreateCall() - this starts the processof calling "Init"
Thread2 calls SingletonObject.Instance.CreateCall() - however as Init has not yet completed this fails
I have tried all sorts of variations of lock() and Mutex, but im not seeing the behaviour I expect. Here is some cut-down code which will hopefully demonstrate what im attempting (Methods prefixxed "X25" are the external calls). Any help appreciated as always.
public class Xot
{
#region Static
static Xot()
{
}
private static readonly Xot instance = new Xot();
public static Xot Instance { get { return instance; } }
#endregion
private Dictionary<int,> calls;
private bool initialised = false;
private Timer waitTimer;
private Xot()
{
calls = new Dictionary<int,>();
waitTimer = new Timer(this.ReadEvents, null, Timeout.Infinite, Timeout.Infinite);
Console.WriteLine("Initialising Xot");
if (!this.initialised)
{
lock (Xot.Instance)
{
int rc = X25.HsX25DllInit(
"10.80.105.102",
0,
1024,
2,
1,
4095,
1);
if (rc == X25.HSX25DLL_RC_OK)
{
initialised = true;
this.waitTimer.Change(0, 15);
}
else
{
throw new Exception(String.Format("Failed to initialised Xot. RC={0}", rc));
}
}
}
}
~Xot()
{
if (this.initialised)
{
Console.WriteLine("Shutting Down Xot");
int rc = X25.HsX25DllShutDown(0);
if (rc != X25.HSX25DLL_RC_OK)
{
throw new Exception(String.Format("Failed to shut down X25 [RC={0}]", rc));
}
this.waitTimer.Change(Timeout.Infinite, Timeout.Infinite);
this.initialised = false;
}
}
private void CheckInit()
{
if (!this.initialised)
throw new InvalidOperationException("Not initialised");
}
public XotCall CreateCall()
{
this.CheckInit();
XotCall call = new XotCall(this);
return call;
}
}
|
|
|
|
|
Just a couple of comments:
1) Your lock and if statement are backwards. 2 threads could get past the if statement. One would pass the lock and do the init, the other would hang at the lock. When the first exited the lock, the second would then be released and pass the lock and do the init again.
2) I wouldn't lock on the instance. Mainly because it's public (advised against). If you must use a lock, create a private lock object instead.
3) I wouldn't put the shut down code in a finaliser. Finalisers aren't guaranteed to be run, and if a finaliser blocks or throws an exception it can screw up your garbage collector thread - You definitely shouldn't be throwing exceptions from a finaliser, it will kill the garbage collector, and the exception will never get reported. I'd do it with a dispose pattern (and put the code inside the if block so it's only called when disposing and not when finalising) and make sure you call dispose manually from your applications shutdown routines.
4) It's a singleton. That means the constructor only gets called once. You've used a thread safe singleton patten, so unless I've missed something I think you don't need the initialised flag or the lock at all. Just ditch the lock and flag entirely and trust the singleton pattern to only create the object and call the constructor once.
Simon
|
|
|
|
|
How can we find the next highest value in the binary tree?
We have a binary tree and an number is being input. We need to find the next highest number.
|
|
|
|
|
This sounds a lot like a homework question. Sorry if it's not, but I hope you understand I'm not going to just give the answer out. It's fairly simply though, you should be able to figure it out. Wikipedia[^] has loads of info on binary trees. You could start by reading up there.
If not, try drawing up a sample binary tree. Pick a number, and see how you would find the next number by traversing the tree.
Simon
|
|
|
|
|
Hi all.
There is any way to restart a console application from itself code?
Thanks.
|
|
|
|
|
You can use Process.Start() to start a new process, and you can use Environment.CommandLine to get the command line the program was started with.
Simon
|
|
|
|
|
hi..
I created a windows application, I have 1 Picturebox & 1 button, when I click the button Picturebox should rotate (means flip), and the user should get 2D effect of the Picturebox (like in power point presentation the animation that we use to switch between the slides).
Any solution’s or links related to my question are kindly acceptable...
Please help me to do this
|
|
|
|
|
System.Drawing.Drawing2d.Matrix.Rotate()
Is this what you are looking for?
Loading signature. Please wait...
|
|
|
|
|
Thanks you d@nish for you reply
I have to rotate the picturebox, and the user should feel that it is rotating while rotating I have the change the image of the picturebox.
|
|
|
|
|
|
pictureBox.Image.RotateFlip([option]) or in the old fashion way with GetPixel() SetPixel(), reordering the pixel array ... anyway i'm sure google would've give you the right answer in a few seconds ... but owh well
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
Dear All,
Iam new to c# window application and also for COM.I have a COM component
which is developed in Visual Basic.Now i want to use this component into
my c# window application.How can i register and use.The COM is in the form
of EXE not in the form of DLL.Please help me out on this.
Thanks & Regards
Veeresh
i want to join this group
|
|
|
|
|
hi
you can register com objects with regsvr32.exe. pass the full filename as parameter.
after registering, add a reference to your project selecting the com object registered before.
visual studio create a wrapper for the com object and add this wrapper as refernece to the project.
regards
|
|
|
|
|
Dear All,
Sorry i dont where to post these kind of questions.its related to COM and also .net so
i posted in all the forums.
Dear Jeo,
Thanks for your help.When iam registring the COM component using the method which specified.
Iam getting the following errors.
c:\xyz\xyz\COMcomponent.exe was loaded,but the DLLRegisterServer entry point was not found.
c:\xyz\xyz\COMcomponent.exe does not apperas to be a .DLL or .OCX file
Please help me on this.
Thanks and Regards
Veeresh
i want to join this group
|
|
|
|
|
in this case your exe ist not a com object. all com object must contain
DLLRegisterServer and DLLUnregisterServer methods. this methods register/unregister
the com object.
|
|
|
|
|
Hi Jeo,
Thanks a lot for help.I will get COM component and i will register.
Thanks and Regards
Veeresh
i want to join this group
|
|
|
|
|
|
DO NOT CROSSPOST the same question in multiple forums. You spammed about half the forums on the site...
|
|
|
|