|
Yes, you do have a race condition. The lock block's scope is within the try block, so it is essentially
try
{
try
{
Monitor.Lock(s_Lock);
...
}
finally
{
Monitor.Unlock(s_Lock);
}
}
finally
{
if (fs != null)
fs.Close();
}
So yeah, DeleteFile could potentially run in parallel with the finally block.
Moving the lock block outside try/finally solves the problem. And if all you're doing is closing the FileStream in the finally block, you might want to use a using statement instead. Like
lock(s_Lock)
{
using(FileStream fs = new FileStream(...)
{
fs.Read(...);
}
}
Hope that helps.
|
|
|
|
|
Thanks for the help!
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
With Martin Luther King Day approaching, we should all look to eliminate race conditions.
|
|
|
|
|
PIEBALDconsult wrote: With Martin Luther King Day approaching, we should all look to eliminate race conditions.
I have a dream that one day this operating system will rise up and live out the true meaning of its creed "We hold these truths to be self-evident: that all threads are created equal and shall not interfere with each other."
|
|
|
|
|
Hello Everyone!!
I'm trying to add a delegate to a Dictionary<string, object>, hence of running it through IronPython (script file).
I have managed this (look at the code) but now I want to do this dynamic. In other words I don't want
to declare a delegate for every method in my class (ExCode. AddItem in Actor).
The problem is the method CreateDelegate and the first argument. I can't bind a dynamic type representing the type of delegate to create. I have not found a solution for this on CodeProject but where is greatly on the subject.
Dynamic Code Generation vs Reflection By Herbrandson
Fast late-bound invocation through DynamicMethod delegates By Alessandro Febretti
A General Fast Method Invoker By Luyan
This is the code:
<br />
using System.Reflection;<br />
using IronPython.Hosting;<br />
<br />
public class Actor<br />
{<br />
private string objectID;<br />
private int count;<br />
<br />
public void AddItem(string objectID, int count)<br />
{<br />
Console.WriteLine(string.Format("{0}, {1}", objectID, count));<br />
this.objectID = objectID;<br />
this.count = count;<br />
}<br />
}<br />
<br />
public class ActorScript<br />
{<br />
protected delegate void AddItem(string objectID, int count);<br />
protected Dictionary<string, object> locals = new Dictionary<string,object>();<br />
protected Actor actor;<br />
<br />
ActorScript(Actor actor)<br />
{<br />
this.actor = actor;<br />
Initiate();<br />
}<br />
<br />
private void Initiate()<br />
{<br />
MethodInfo methodInfo = typeof(Actor).GetMethod("AddItem", BindingFlags.Public | BindingFlags.Instance);<br />
this.locals.Add("AddItem", Delegate.CreateDelegate(typeof(AddItem), this.actor, methodInfo));<br />
<br />
}<br />
<br />
public void Run(string fileName)<br />
{<br />
PythonEngine engine = new PythonEngine();<br />
engine.ExecuteFile(fileName, this.engine.DefaultModule, this.locals);<br />
}<br />
}<br />
<br />
This is the script file:<br />
<br />
ItemScript.py<br />
AddItem("Sword", 2)<br />
Any help would be appreciated.
Best Regards,
Gywox
modified on Tuesday, January 15, 2008 5:13:06 AM
|
|
|
|
|
Its probably easier to just wrap a delegate like so:
this.locals.Add("AddItem", delegate(string object, int count) { this.AddItem(object, count); })
It might be even easier to use Boo (which has a very python like syntax) as your scripting language - as you can just expose your whole Actor instance to the Boo interpreter (or compile it).
You should probably make sure that IronPython can't reference an object instance as well before you go down this route.
|
|
|
|
|
Hi Mark
One can expose instances to IronPython, but in this case I don't want to.
I have the script function in a database, and I wish to connect the class methods and
the script commands by this mean.
|
|
|
|
|
Messing around with delegates in this way just seems a little messy.
Whats your real objective here? Stopping your script files from affecting the object model too much? Just expose stuff like IScriptActor which has only the functions you want to expose.
|
|
|
|
|
Hi,
Has anybody done a comparison between these 3 component suites? I need to pick one to integrate in my Windows-based app (the app has UI galore). After a quick glance, C1 doesn't seem very structured (has a lot of do-it-all components - the FlexGrid can also do Trees), whereas Infragistics and Syncfusion seem better layed out (I really like Syncfusion's docking manager).
Most likely I'll have to write small apps with each suite to figure out if they have what I need (for example listView drag'n drop is a big one, because now I'm using XCeed and their drag'n drop is a joke), but I thought I'd ask others what's their take on this (speed, feature set, memory footprint, stuff like that). If you haven't compared them, but are currently using one of them, please tell me what you think of it.
thanx
|
|
|
|
|
I don't have any experience with the other two, but I have used Infragistics for both web and windows apps. I would look for something else. Infragisitics has poor documentation and customer support, it seemed to me as though their controls were carelessly rushed to market with the hope that they could be fixed with service packs.
only two letters away from being an asset
|
|
|
|
|
We are using Syncfusion at work for a project under development, and I cannot recommend it to anyone. We've had to put up with buggy controls, not recognizing valid licenses, and horrible support.
I'm sure there are people out there with nothing but good to say about Syncfusion. My co-workers and aren't among them.
I cannot really give you any advice on the Component1 or Infragistics, but I have used DevExpress' controls, and they work quite nicely. I have noticed no bugs whatsoever, and their support is responsive and helpful!
|
|
|
|
|
Hmm.. DevExpress wasn't on my list, but I'll sure take a look, now that you brought it up!
Could you tell me what controls did you find buggy in Syncfusion?
thanx
|
|
|
|
|
i worked with both infragistics and syncfusion controls (use some controls)
and it is true as said by mark infragistics lacks good documentation
u have to spent a time on it's forumn to do something...
syncfusion's grid is more fast than the infragistic's grid
some of infragistic's control are hard to implement only due to lack of documentation
|
|
|
|
|
I started to use SyncFunsion, dont know about bug, but one thing I know... infragitics it is some time real hard to work with them as lack of documentation. this have been a problem for many years. Oscar Rangel
|
|
|
|
|
hey guys, its up again, i've been working on a card project using c# 4 a while now and i am using ACR38 SDK. i read through the tutorials and it seemed easy but i just realised its not as easy as it is. i see some hexadecimal codes that i do not even understand how to implement. can any1 help? i need to know in a simple way how to communicate with the cards. (read and write to it) thanx y'all
|
|
|
|
|
I have been given the task of developing a program that will run on a clent machine and interact with a MySQL database on an internal server. It is for a phone call loggin system. Basically, each day when the first phone call is made, a csv text file is created and information appended about each call - numbers, extensions, call duration etc is recorded automatically.
What my clients want is for this text file to be uploaded to their internal MySQL using some GUI on a client machine (which I presume can be built using .NET Forms).
My thougts are: build a Forms based GUI that handles file processing, extract the information and add the data to the MySQL database.
Client machine is windows 2000, server is Windows 2003. Can anyone see any problems with this approach? Does .NET 2.0 need to be installed on either machine? I've only ever used C# in ASP.NET.
Thanks in advance!
|
|
|
|
|
The .NET framework wil only be required on the client machine. If connecting to MySQL I reccommend downloading Connector/Net from the MySQL site[^]. Simply add a refererence to the dll and everything you need will be availaible via the MySql.Data namespace.
|
|
|
|
|
Of course the .NET Framework must be installed on the machine where the code is running. If you are connecting to the server running mySql via ADO.NET, the no, the .NET Framework does not need to be on the server.
only two letters away from being an asset
|
|
|
|
|
Ok thanks. Other than that you don't see a problem connecting client with server and database?
|
|
|
|
|
No, it's really easy actually
Obviously, you need a MySQL username/password on the database server that has the required privileges and the correct port open in the firewall.
Experiment on a seperate machine if possible first - it won't go down very well if you accidentaly DROP an existing database/table/user/etc... ! You can get MySql here[^]
|
|
|
|
|
|
Everyones answered your actual question - but one thing that strikes me, if the file is generated automatically, then it also can probably be uploaded and processed automatically. Seems odd the user would have to upload the file by hand...
Have a look at the FileSystemWatcher(?) class in the framework.
|
|
|
|
|
Yes I considered that part. Ideally it should be automated. Thanks I will look into the FileSystemWatcher.
|
|
|
|
|
Hi,
If I add too many design time features and GUI on my Windows Custom Control, will that have any performance effect in run time ?
Thanks.
|
|
|
|
|
It depends what you are using those design time features are for? If they add bloat to the runtime, then they will have a performance effect.
|
|
|
|