|
That depends on what you are converting. For an example, the implementation of Convert.ToInt32(Int16) looks like this:
public static int ToInt32(Int16 value) {<br />
return (int)value;<br />
}
So, the only difference from using the cast directly is the method call. And if the compiler is clever enough, it will never even do the method call, but simply use the code from the method inline, so there will be no difference at all in the final executable code.
However, one thing is certain. The call to Convert.Int32 is never faster than a direct cast.
---
b { font-weight: normal; }
|
|
|
|
|
Hi all,
I’m using the comboBox to show values to select one of them
Those values are from a database, where there are Ids and values.
So, the DisplayMember is the value and the ValueMember is the ID.
the first worked but the second refuses to work at all. And I don’t know why..?
<br />
comboBox1.DataSource = dataSet3.Tables["DESIGNATION_EDIT"];<br />
comboBox1.ValueMember = "D_ID";<br />
comboBox1.DisplayMember = "D_TYPE";<br />
then i need to use it here where the problem appears
<br />
newrow[11]=comboBox1.ValueMember;<br />
table.Rows.Add(newrow);<br />
if any body could help.., I’ll be grateful.
|
|
|
|
|
moonangel_bio wrote: hen i need to use it here where the problem appears
newrow[11]=comboBox1.ValueMember;
table.Rows.Add(newrow);
what actually happens ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
when i try to add a new record using my application, this messeage appears:
An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll
Additional information: System.FormatException: Input string was not in a correct format.
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.Convert.ToInt32(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Convert.ToInt32(Object value)
at System.Data.Common.Int32Storage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store <d_id> in S_DESIGNATION_ID Column. Expected type is Int32.
where D_ID is the ValueMember of the comboBox and i need it to be stored in S_DESIGNATION_ID in the data base
|
|
|
|
|
Well, now that you're told us the problem, it's obvious. A string that's coming in is not a number, and it needs to be.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello Friends,
I am new here. For our senior project at school, we are using .Net C#. And we want to compile and deploy C Code in C3. How can we accomplish this?
I surely be so glad to receive your help.
Take it easy, guys!
|
|
|
|
|
You can call functions written in C compiled to a .dll from .NET by providing what is effectively the function prototype and marking it with a DllImportAttribute . More information can be found here[^].
|
|
|
|
|
Your other option is to wrap it in a C++/CLI project, so you can call it using .NET.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
It's probably not that hard to draw outside the control boundaries, but it's not very good to do so. You will have problems with the drop down disappearing if the controls behind it is redrawn, and the code to hide it would have to find all the controls behind it to force a redraw.
Just create a new control for the dropdown. That way the control will be able to properly handle redraws, it won't be drawn over by other controls, and hiding it will be simple, as the controls behind it will automatically redraw when it's removed.
---
b { font-weight: normal; }
|
|
|
|
|
Is there a quick way of retrieving the hearder from an RTF?
thx
Nana
|
|
|
|
|
I was Testing my program, which is a thread/database intense program. I ran it in VS, and it runs perfectly and all of a sudden gives me a popup box with this message:
Managed Debugging Assistant 'RaceOnRCWCleanup' has detected a problem in 'C:\Documents and Settings\Wallace\My Documents\Visual Studio 2005\Projects\Visual Waiter\Visual Waiter\VWServer\bin\Debug\VWServer.vshost.exe'.
Additional Information: An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss.
What does this mean? whats RCW?
It looks like to be that everytime this message pops up, the program is stopped at
dbConnection.Close();
Maybe I am closing the connection somewhere else? so i have 2 .Close() somehow causing race condition?
I used threadpool in my prgoram to handle the threads, it seems like that it is only running 2 threads at the same time. I hope there is a property i can set in Threadpool that i can increase the amount of concurrent running threads??
-- modified at 15:37 Thursday 19th January, 2006
|
|
|
|
|
2hdass wrote: Maybe I am closing the connection somewhere else?
It actually sounds like your trying to close a connection that still had a query pending. Perhaps your opening a connection on one thread and running a query on that connection on another thread???
RCW stands for Runtime Callable Wrapper. It's the wrapper code that your .NET Managed code calls to get at unmanaged COM code, like controls or libraries.
There is no property to increase the number of concurrently runnable threads. What may be limiting the number of threads is whatever your calling in those threads. Like the SQL server your connecting to doesn't have any more connection licenses? Or the server your connecting to doesn't have any more open connections?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
So how can we avoid This RCW error being thrown from that dll while calling them from another .net application via multithreading??
can we pls reply asap??
|
|
|
|
|
Write better code?
How did you expect me to answer that? There are so many ways of writing database access code and even more ways of doing it wrong it's impossible for anyone to guess at what you're doing and how you're doing it.
About the best I can do is tell you that your database code should follow a pattern: Open the connection to the database as late as possible, do your database work as quickly as possible, then close the connection as early as possible. Do not open a connection as part of a class to make it visible anywhere within the class. You will have less control over the lifetime of the connection.
|
|
|
|
|
I've got a project in VS2003 where I've added a number of images and a video clip as an embedded resource on 'Build Action'. I can access the images easy enough by using the following code:
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(GetType(), "sampleImage.jpg"); this.pictureBox1.Image = bitmap;
The problem is accessing the embedded .AVI; both the ActiveX Windows Media Player and the DirectX AudioVideoPlayback require a string pointing to a file?
Accessing Video File Thru ActiveX Windows Media Player Control:
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;
this.axWindowsMediaPlayer1.URL = "sampleVideo.avi";
Accessing Video File Thru DirectX 9:
using Microsoft.DirectX.AudioVideoPlayback;
Video vid = new Video("sampleVideo.avi", false);
Any help would be greatly appreciated.
"She folds her legs...in doing so I glimpse Xanadu."--Gilby
|
|
|
|
|
Hi,
I want to do some actions immdiately after the form load automatically.
How do I do it. If I do in form load then it happens before the form is loaded. But I want to do after the form is loaded.
How do I do it..Thanks.
|
|
|
|
|
Hi!
One solution could be to attach an event handler for Application.Idle in the Load event handler and then perform your work there:
private void myForm_Load(object sender, EventArgs e)
{
Application.Idle += new EventHandler(app_Idle);
}
private void app_Idle(object sender, EventArgs e)
{
Application.Idle -= new EventHandler(app_Idle);
MessageBox.Show("This happens almost immediately after myForm_Load has returned!");
} Regards,
mav
|
|
|
|
|
|
Or if you're using .net 2
myForm.Shown += formStartup;
void formStartup(object sender, EventArgs e)
{
}
|
|
|
|
|
Perfectly working. Thanks a lot.
|
|
|
|
|
I'm working on a project with some pretty math intensive calculations that must output double values. After much testing, it was determined that we have an accuracy out to 10 digits after the decimal point. This is adequate for what I'm working with so we kept going forward.
Now, in the next phase of the project, comparisons have to be made between two structures that contain the double results, so I overloaded Equals() to do a comparison to the tested accuracy. Immediately I found some big problems with this. Because of the way Equals() is determined, I run into the problem where the following is true: A==B, B==C, A!=C. I'm a bit stumped on how to fix this. There must be a way, but I'm not really seeing anything.
I created the following test code to illustrate my problem:
using System;
using System.Collections;
namespace TestIt
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
SomeStruct val1 = new SomeStruct(1.0);
SomeStruct val2 = new SomeStruct(1.0);
SomeStruct val3 = new SomeStruct(1.00000000009999);
SomeStruct val4 = new SomeStruct(0.99999999999);
Console.WriteLine("Starting . . .");
if (val1.Equals(val2))
Console.WriteLine("val1 == val2");
if (val2.Equals(val3))
Console.WriteLine("val2 == val3");
if (val1.Equals(val3))
Console.WriteLine("val1 == val3");
if (val1.Equals(val4))
Console.WriteLine("val1 == val4");
if (val3.Equals(val4))
Console.WriteLine("val3 == val4");
Console.WriteLine("Done");
}
public struct SomeStruct
{
private static double accuracy = 0.0000000001;
public double Value;
public SomeStruct(double val)
{
Value = val;
}
public override bool Equals(object obj)
{
if (obj is SomeStruct)
return (Math.Abs(Value - ((SomeStruct)obj).Value) < accuracy);
return false;
}
}
}
}
Anyone have any ideas?
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
I think you will find val3 - val4 is greater then accuracy . The program is working as written.
You will have to change the value of accuracy to get the results you want. If you want to use accuracy as defined, you may want to truncate all your numbers to 10 digits before testing for equality.
Take a look at double.Epsilon . It contains a number you can use to test for equality on doubles but, it carries it to the least significant digit.
Also, take a look at the Decimal structure. It may suit your needs out of the box.
|
|
|
|
|
Yes, val3 - val4 is greater than accuracy, but that leaves me with the problem that val3 == val1 is true, val1 == val4 is true, but val3 == val4 is false. A==B, B==C therefore A==C is a basic mathematical principal that this is breaking, and I'm afraid will cause problems, and I can't figure out a way around it.
Truncation isn't quite right either, that way 1.0000000001 and 1.00000000009 wouldn't match up.
I've since rewritten the equality method, to get much better results but no matter how I change it, I still can't get around that basic problem.
BTW, I've thought about using the Decimal structure for internal calculations, but I don't know how much it would gain me when most of the intermediate results will be stored outside of my class and will be in double.
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
You will get better results if you round each value and then compare them, instead of checking the sum of the rounding errors.
Math.Round(this.Value, 10) == Math.Round(((SomeStruct)obj).Value, 10)
---
b { font-weight: normal; }
|
|
|
|