|
Hi,
do you know if there is an exam available for windows c# 2.0 ?
Thanks
|
|
|
|
|
|
Hi
I have created a utility class which contains static methods to do some utility functions. I believe that only one instance of this method is created for this class and all objects use the same instance.
My concern is this: If multiple threads access the method simultaneously, are the variables in the static method used thread safe? is it possible that they mgith be corrupt?
Please advise. I am wondering whether to make these methods instance methods.
Thanks
TSR
|
|
|
|
|
Local variables inside methods are always stored on the stack, and each thread has its own stack, so this is absolutely thread-safe.
Static fields inside the class are something different...
|
|
|
|
|
|
tsramkumar wrote:
y one instance of this method is created for this class
Not really. There are no instances for methods, static or otherwise. When your application loads up, these methods (the compiled code, actually) are loaded into memory (a special section called .text) and that's it.
That memory is totally different from memory used by local variables. Local variables are created on the stack and each invocation of the function creates them, so yeah, you are safe as long as the variables you refer to are local variables.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks. I have only local variables in my static method (it does call another static method in a utility class, but that too uses local variables only). So as long as I use only local variables in static methods, the code should be thread safe right.
Thanks once again for clarifying this.
Ram.
|
|
|
|
|
Anything static must be treated with care in a MT system. As you have guessed any thread could access it at any time causing wackiness to ensue. In general I would avoid any static members in objects that are going to be in an MT system. static methods aren't as toxic because any locals are stored on the stack of the thread but can be problematic if it access other things that have static members or worse members.
|
|
|
|
|
Hello,
Does anyone know any sources where I can find the function, or any info that would be able to calculate IRR for a range of values, with the given initial rate?
I am thinking of using recursion, any ideas?
Thank you
|
|
|
|
|
There are well known staticstical formulas for this. We did them all in 1st year in University. I doubt any one of them included recursion, as we used calculators. Maybe a loop or 2
xacc-ide 0.0.99-preview
|
|
|
|
|
I know the formula, and indeed it's pretty simple. However, how can you use a loop or two, if you don't know how many times you will be calculating the IRR. Meaning, the first value of IRR is just a guess, and then the function will go through an array of values, to calculate the specific sum, and if the sum is not equal zero, then it picks another IRR rate value (based on a certain rule), and does the same sum operation. Therefore, it's not a loop or 2.
|
|
|
|
|
Hi there!
I hope you guys can help me, here's my problem:
I have a form (Form1) with a button (Button1) which open another form (Form2) as such:
<br />
Form2 frm2 = new Form2()<br />
<br />
frm2.Show();<br />
On the second form (Form2) I have a DataGridView with this code:
<br />
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)<br />
{<br />
this.Close();<br />
}<br />
My goal is to close the second form when the user double-clicks (makes a selection) in the DataGridView. I've tried more than 20 events and I always have the same problem:
Object reference not set to an instance of an object.
at System.Windows.Forms.DataGridView.HitTest(Int32 x, Int32 y)
Can you guys help me? Thanks!
|
|
|
|
|
I tried this with a DataGrid control and had no problems... where are you getting this DataGridView control?
|
|
|
|
|
Ahhhh, of course, sorry!
I'm using Visual Studio 2005 Beta 2... It's a grid that comes with .NET 2.0. It's VERY useful, much better than the old DataGrid IMHO.
|
|
|
|
|
Ahh I see... I have 2005 Beta 2 but am not willing to install it in my work environment. Until I get build a test env, I cannot provide any good help to ya.
Try these two methods though.
1.) Create a timer set to 100ms and have the timer_elasped event close the form. and start the timer inside your douleclick method. This would allow the method to complete and then run the close time. This is not a good way to do it, but probably the easiest.
2.) Create an event delegate to close the form. Inside the code for the control_click call the method this.Invoke(new delegatename(delegatemethod)); Then in the delegatemethod() call this.close; This is the thread safe way to run form methods on a click. Hit me back if you need realcode examples and I'll make some for ya
|
|
|
|
|
The timer would probably work but as you said, it's not a very good way of doing it.
The delegate doesn't work AFAIK, I receive this error:
Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
The invoke calls the delegated method ASAP (before the HitTest did it's job I guess) and the same error (more or less) happens... I think I'll solve the problem in another way (adding a button comes to mind).
Thanks again for your help
|
|
|
|
|
My mistake, I should've used BeginInvoke instead of Invoke.
This line of code works perfect:
this.BeginInvoke(new MethodInvoker(this.Close));
Thanks again for your help!
|
|
|
|
|
I have an app with two dialogs, one opened by the second. With 2 monitors the 2nd dialog opens on the same monitor if I set it to open in a normal state. IF i have it set to open maximized it always opens on monitor1, regardless of which monitor the first is on. Is there a way to change this behavior.
|
|
|
|
|
You could possibly programatically set the dialog to open in coords of the second monitor first and then change the property to Maximized once the dialog has fully loaded.
|
|
|
|
|
I tried doing a programmatic maximize in the constructor, it didn't work. The form still opened maximized on monitor1. When I demaximized it the normal version was on monitor two, and manually maxing it left it on mon2 just like before.
|
|
|
|
|
You don't want to do it in the constructor because you don't want it to maximize until it has been fully created and painted.
|
|
|
|
|
Where should I move the call to then?
|
|
|
|
|
Try it in the form_load event. I'll toy with it a bit as well as I have dual monitors also.
|
|
|
|
|
Yes, this worked for me: (My second monitor is on the LEFT of the screen... if yours is on the right, you would have to move it to a coord PAST the first monitor)
<code>
private void Form2_Load(object sender, System.EventArgs e)
{
this.Left = -458;
this.WindowState = FormWindowState.Maximized;
}
</code>
|
|
|
|
|
I've got a tabcontrol with a number of databound textboxes on a tabpage
(Form1). I've got a button that the user clicks that opens a dialog (Form2)
and does a lookup from a database. The user makes a selection and chooses a
button wired dialog.ok to close the dialog (form2) and populate the fields on the tabcontrol (Form1). It all works except the textboxes don't retain the new data when I tab across to another tab page.
Code To Open Dialog (Form1)=========================
private void btnLmoLookup_Click(object sender, System.EventArgs e)
{
Form2 LmoLookup = new Form2();
LmoLookup.StartPosition = FormStartPosition.CenterParent;
if( LmoLookup.ShowDialog() == DialogResult.OK )
{
txtBoxDocName.Text = LmoLookup.docFullName;
}
LmoLookup.Dispose();
}
Code To Create Public Variable (Form2)======================
public string docFullName
{
get{return
this.dsExtPhysLookup1.Tables["tblExternalPhysicians"].Rows[this.listBox1.SelectedIndex]["docFullName"].ToString();}
}
|
|
|
|