|
Don't use ReaderWriterLock , there are bugs in it which can cause writer starvation, performance issues, and resource leaks. Use the ReaderWriterLocksSlim class from the .NET 3 framework instead, or use one of the high-performance locks from the free Power Threading library.
|
|
|
|
|
Thanks for clearing that.
Judah Himango wrote: use one of the high-performance locks from the free Power Threading library.
Can you tell me which are these ? Do you mean Monitor.Enter type of lock ?
|
|
|
|
|
|
Thanks a lot for the reply, well, I mentioned that my application is an ASP.NET application but the question is about thread safety in C# not about ASP.NET, and the code in my post would look exactly the same in a Windows Forms application, right? Nothing ASP.NET about it .. so, objection overruled
|
|
|
|
|
Thank you guys for all your replies, actually I'm using .NET 2.0 and wasn't planning to use any external libraries, so it seems a little confusing now ..
|
|
|
|
|
I am creating a usre control which needs to filter a generic list object based on text entered by the user
the filter must be real time.
The problem is that i need to create a generic control which allows you to bind a custom object to the control and then
in visual studio display all the members of the class. you then select which members are avaliable for user criteria to
be searched on.
Thank you
|
|
|
|
|
I am writing a c# application where I need to use matlab functions from my c# sharp code. From the beginning I used the Matlab Automation Server, which worked fine on my computer which has Matlab 7.4.0 (R2007a) installed. However, the application needs to be usable on computers with older versions of Matlab, and it turned out that the automation server can't be used then.
Now I am trying to solve this problem using Matlab Compiler to create dll files of my matlab functions and then call them from c#, based on these two code examples: http://www.mathworks.com/support/solutions/data/1-X1PFC.html
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12987&objectType=file
My problem has to do with passing arrays to and from my matlab functions. As long as I only use scalar values or arrays containing only one value, everything works fine, but as soon as the array contains more than one value an error occurs.
This is my code:
The copy.m matlab function only returns a copy of the input argument:
function y = copy(a)<br />
y=a;
This is my c# code (the try and catch statements have been removed here to make more readable):
[DllImport(@"copy.dll")]<br />
private static extern bool copyInitialize();<br />
[DllImport(@"copy.dll")]<br />
private static extern void copyTerminate();<br />
[DllImport(@"copy.dll")]<br />
private static extern bool mlfCopy(int num, ref IntPtr output, [In]IntPtr input);<br />
<br />
[DllImport(@"mclmcrrt76.dll")]<br />
private static extern IntPtr mxCreateDoubleMatrix_700([In]Int32 numRows, [In]Int32 numCols, [In]Int32 mxComplexity);<br />
[DllImport(@"mclmcrrt76.dll")]<br />
private static extern IntPtr mxGetPr([In]IntPtr mxArray);<br />
[DllImport(@"mclmcrrt76.dll")]<br />
private static extern bool mclInitializeApplication(string options, int count);<br />
[DllImport(@"mclmcrrt76.dll")]<br />
private static extern void mclTerminateApplication();<br />
<br />
static void Main(string[] args)<br />
{<br />
double[] copyInput = { 1.0};<br />
<br />
mclInitializeApplication("NULL", 0);<br />
copyInitialize();<br />
<br />
IntPtr inValA = mxCreateDoubleMatrix_700(copyInput.Length, 1, 0);<br />
<br />
int size = Marshal.SizeOf(copyInput [0]) * copyInput.Length;<br />
<br />
IntPtr outVal = Marshal.AllocHGlobal(size);<br />
<br />
Marshal.Copy(copyInput , 0, inValA, copyInput .Length);<br />
<br />
mlfCopy(1, ref outVal, inValA);<br />
<br />
double[] copyAns = new double[copyInput .Length];<br />
Marshal.Copy(outVal, copyAns, 0, copyInput.Length);<br />
<br />
copyTerminate();<br />
mclTerminateApplication();
When running this code the returned value is identical to the value in copyInput, however, as soon as the size of copyInput is changed (double[] copyInput = { 1.0, 2.0}; ) an error occurs (without any more information than a standard windows error message). I have also tried to use
[DllImport(@"copy.dll")]<br />
private static extern bool mlxCopy(int numOut, ref IntPtr output, int numIn, [In]IntPtr input);
and
mlxCopy(1, ref outVal, 1, inValA);
Instead of the mlfCopy, but this doesn't work either.
Is there anyone who has an idea of how to solve this problem? What I really need is to be able to pass two-dimensional arrays to and from matlab functions.
Thanks in advance!
|
|
|
|
|
can any one help me!!
I want to create a application like a photoshop in .net so please help me
jeny
|
|
|
|
|
Hmmm... Where do you start with this one? Codeproject? If you don't understand how ridiculous a question this is....
Try getting involved with an open source project that is making a photoshop clone.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Download the source to paint.net and have a look at it. Although, this seems a little bit of an ambitious project for you. Are you sure you want to attempt this on your own.
|
|
|
|
|
|
BWAHAHAHA
|
|
|
|
|
prachi14 wrote: I want to create a application like a photoshop in .net so please help me
Since I'm currently developing a new OS , like Windows XP in .NET , I have no spare time to help you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Surely this should have been posted on 1st April.
If you don't know where to start I suspect you have absolutely no chance of success.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
|
Hey
I have created a metode to create RadiobuttonList dynamically but when i show it in my page end i chec them to false or true and when i click the button all radiobutton is coming back to true.
I have a function to read wgat user have selected :
Hope i can help. her is som code to create radiobuttonlist:
foreach (DataRow dr in ds.Tables[0].Rows)
{
Label li = new Label();
System.Web.UI.WebControls.ListItem ls = new System.Web.UI.WebControls.ListItem();
RadioButtonList rl = new RadioButtonList();
rl.Items.Add(new System.Web.UI.WebControls.ListItem("Inkl", dr["Type"].ToString()));
rl.Items.Add(new System.Web.UI.WebControls.ListItem("Eks", dr["Type"].ToString()));
rl.RepeatDirection = RepeatDirection.Horizontal;
Panel2.Controls.Add(li);
Panel2.Controls.Add(rl); //tilføjer dem til panelet
}
then when i click a button hwo called checkthevalue, i called this metode:
foreach (Control cr in Panel2.Controls)
{
if (cr is RadioButtonList)
{
RadioButtonList rb = (RadioButtonList)cr;
foreach (System.Web.UI.WebControls.ListItem ls in rb.Items)
{
if (ls.Selected && rb.SelectedItem.Text == "Eks")
{
//this ad a line to pdf file
document.Add(new Paragraph("-" + rb.SelectedItem.Value.ToString(), FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12)));
}
}
}
}
Hope i can help me.
|
|
|
|
|
I am designing a custom component (Non visible componenent). I inherited my class from System.ComponentModel.Component class. I know Component implements IDisposable . But how could I release resources used by my control ? Component class doesn't allow overriding Dispose . So how to dispose the objects used in my custom control ? Do I need to implement IComponent directly in my custom control ?
|
|
|
|
|
Declare the Dispose in your derived class with the new qualifier.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
carbon_golem wrote: Declare the Dispose in your derived class with the new qualifier.
Thanks for the reply. But it won't work when ((IDisposable)componentInstance).Dispose() called as it's not a IDisposable member. And I think it's not a good practice to use new keyword which hides the base method.
|
|
|
|
|
Ok, Implement IDisposable on your derived class and forward the call to the base class's Dispose method. As for using the new modifier, FxCop doesn't complain about it.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Thanks, I will give a try
carbon_golem wrote: FxCop doesn't complain about it.
FxCop ? I am pretty new to that. Let me try using that. Thanks again
|
|
|
|
|
Component offers a void Disposing(bool) virtual function. Override that.
See also Implementing a Dispose method[^] in the .NET documentation.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Thanks Mike. I found that
|
|
|
|
|
Hi,
Im trying to get the postdata string in beforenavigate2 event.
The function i:
<br />
void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) {<br />
byte[] myBytes = System.Text.Encoding.ASCII.GetString(PostData);<br />
MessageBox.Show(myBytes.ToString());<br />
<br />
<br />
}<br />
As you can see, im trying several methods to convert the postdata to a string, but im not able to...
MessageBox.Show(PostData.ToString()); shows "System.bytes[]".
I've found this :
http://support.microsoft.com/kb/256195
but the examples are on Visual Basic and C++, and im not able to convert that code to c#
Can anybody help plz?
|
|
|
|
|
byte[] myBytes = (byte[])PostData;
string post = ASCIIEncoding.ASCII.GetString(myBytes);
MessageBox.Show(post);
That was the solution!!!
|
|
|
|