|
I discovered the problem. I had several massive arrays initialized in code as doubles. Something like this:
namespace MusicSynthesizer
{
public partial class Oscillator
{
#region Sawtooth Waveforms
private static readonly double[][] SawtoothWaveforms =
{
new double[]
{
0,
0.99999999999977,
0.765255336254772,
0.90346140078622,
0.804406680287037,
0.880594209485646,
0.817554516488886,
These values are out of range for floats. So when I changed the array type to float without reducing the values of the constants, it caused Visual Studio to freeze.
It would have been nice to have gotten an error message saying, "Hey! These numbers are too big for floats!" instead of it freezing without leaving a clue as to why.
|
|
|
|
|
Leslie Sanford wrote: I did some primitive test and operations with floats seemed to be faster (can anyone confirm this?).
The performance depends on so much more than the data type, so one can not generally say that either of the types are faster.
Internally the processor does all floating point operations using doubles, so all floats has to be converted to double before they can be used. That suggests that doubles would be more effective.
On the other hand, doubles are larger than floats, so if you for example are working with a certain number of numbers, they might all fit in the cache if they are floats, and not if they are doubles.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for your response! I've learned something. I will stick with doubles for now and look for other ways to optimize my code.
|
|
|
|
|
Hi,
I am using the webbroser control in winforms and find that during the page load operation, the application itself hangs in some systems. This is not reproducable in all the systems. Here an XML file is being generated and it displayed in the web browser control using XSL. Can anyone help me out in this issue...
Thanks in advance
Thanks and Regards
Madhu
|
|
|
|
|
Hi, currently I make a Login system with MySQL Connector.
My App is a MDI Application.
1. When the program starts, it asks for User login and if success, there will be a Connection Object that I can access in all Forms (MDI Parent Form, and its MDI Child.
How can I save the success connection into an object so that
I can use(access) that object in another MDI Child to make another connection to MySQL?
Thanks for your help.
Enjoy It!
|
|
|
|
|
You don't. Proper database access means you do NOT hold open a connection to the database. You open a connection, do your business, and close it. If you need database access further in your application, create a new connection when you need it and close it when you don't.
Why? Because SQL licenses, not MySQL obviously, are expensive!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I understand that. What I meant is,
What I meant by Success Connection is the correct parameter about the connection.
In other word, I want a global variable that stores the Connection Parameters (like: Server Name, Database Name, Username and Password), and I can access that variable in any Forms (Parent or Child) to make a connection without transfer variable from Parent to Child.
Enjoy It!
|
|
|
|
|
OK. In that case, all you have to do is create a static class that exposes a method to return a connection object. That class can manage the settings on its own, probably getting the settings from the app.config file or some other place.
Static classes and methods don't need an instance to work. You can call them from anywhere in your project, so long as they're public.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Does that(create static class) work for functions or procedure too?
and, thanks that really helps.
Enjoy It!
|
|
|
|
|
Functions and Procedures are no different, and they're actually called "methods".
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi dear friends.
I have a problem with the shortcur menus and this is that I want select multiple files with my shortcut menu for adding in my program. now I'm using this registery key :
[HKEY_CLASSES_ROOT\*\shell]
[HKEY_CLASSES_ROOT\*\shell\myApp]
@="myApp"
[HKEY_CLASSES_ROOT\*\shell\myApp\command]
@="c:\\myApps\\WindowsApplication2.exe \"%L\""
but my application just show me 1 of the files that I'm selected in explorer.
I think the problem is "%L" , but I don't know What I must do.
in the other language I want to open more than 1 file with the shortcut to my Apploication.
-----------------------------
and another problem that I have with this is this that I wanna select any file type with the shortcut menu. but I can't find better way than this that add "shell" to the "*" key.
what is the true way?
thanks!
public static arraylist OVELISAX(arraylist friendship){
//my life
}
|
|
|
|
|
Hi everyone,
I created a help project, now I want to display the help project when the user clicks a menu. But I can't use the Help class the codes below is giving me error.
private void mnuUserGuide_Click(object sender, System.EventArgs e)
{
Help.ShowHelp(this, helpProvider1.HelpNamespace);
}
error:
The type or namespace name 'ShowHelp' does not exist in the class or namespace 'Help' (are you missing an assembly reference?)
Please advice and thanks in advance!
|
|
|
|
|
Ahh...i'm so stupid . I created a namespace "Help".
|
|
|
|
|
hi
i want to connect to Sqlserver 2000 from client (i done this step by create Login name as 'Guest'),but when i want to Create Database by Code,the following message shown me :
System.Data.SqlClient.SqlException: SELECT permission denied on object 'sysdatabases', database 'master', owner 'dbo'.
CREATE DATABASE permission denied in database 'master'.
...
where is the problem and how to solve it ?
|
|
|
|
|
Are you using SQL authentication (i.e. supplying a user name & password in the connection string)? If so, that user must have create rights in the SQL server instance. If you need help with that, I suggest asking in SQL forum[^].
|
|
|
|
|
You might be running into the problem creating the database with the Guest user. Guest should not have certain permissions to the database.
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|
|
Hi,
I'm having troubles closing my application with a Thread. Here is my code:
public partial class Form1 : Form
{
private Thread comReadThread;
private Boolean comReadThreadRunning;
private SerialPort comPort;
delegate void SetTextCallback(string text);
public Form1()
{
comReadThread = new Thread(new ThreadStart(this.comReadThreadProc));
comReadThreadRunning = true;
comPort = new SerialPort();
InitializeComponent();
comPort.PortName = "COM1";
comPort.ReadTimeout = 500;
comPort.WriteTimeout = 500;
comPort.BaudRate = 9600;
comPort.Open();
InitializeThreads();
}
private void InitializeThreads()
{
comReadThread.Start();
}
private void comReadThreadProc()
{
byte readByte;
StringBuilder readLine = new StringBuilder();
while (this.comReadThreadRunning)
{
try
{
readByte = (byte)this.comPort.ReadByte();
if (readByte != '\r')
{
readLine.Append((char)readByte);
}
else
{
String readString = readLine.ToString();
String[] splitStrings = readString.Split(new string[] {"°C"}, 5,StringSplitOptions.None);
if (splitStrings.Length > 0)
this.SetText(splitStrings[0]);
readLine = new StringBuilder();
}
}
catch (TimeoutException)
{
}
}
}
private void SetText(string text)
{
if (this.currentTempLabel.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.currentTempLabel.Invoke(d, new object[] { text });
Thread.Sleep(10);
}
else
{
this.currentTempLabel.Text = text;
}
}
private void button1_Click(object sender, EventArgs e)
{
comReadThreadRunning = false;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
comReadThreadRunning = false;
comReadThread.Join();
}
}
Closing the main form should set the boolean variable "comReadThreadRunning" to false, so that the while-loop in the thread-proc should quit. The "comReadThread.Join()" call causes my app to freeze then. Does anybody of you know why? I think it has something to do with my delegate for the UI updates.
Thanks for reading and best regards,
Rainer
-- modified at 18:25 Sunday 3rd December, 2006
|
|
|
|
|
comReadThread = new Thread(new ThreadStart(this.comReadThreadProc));
comReadThread.IsBackground = true;
|
|
|
|
|
Thank you for your quick post(!),
but that did not change anything ...
|
|
|
|
|
Try setting comReadThread to be a volatile variable:
volatile bool comReadThreadRunning;
|
|
|
|
|
Increasing the amount of waiting time at "Thread.Sleep()" solved my problem. I think, there where to many delegates:
private void SetText(string text)
{
if (this.currentTempLabel.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.currentTempLabel.Invoke(d, new object[] { text });
Thread.Sleep(500);
}
else
{
this.currentTempLabel.Text = text;
}
}
|
|
|
|
|
p.s. Instead of doing invokes from a background thread, have you looked at using System.ComponentModel.BackgroundWorker ? It's saved me quite a few headaches.
|
|
|
|
|
You're running into the classic deadlock problem. The Form1_FormClosing event is triggered on the UI thread through the message pump. You block execution of the event, waiting for comReadThread.Join . Imagine if at that point of time, comReadThreadProc reads a line and calls SetText . SetText then quite rightly calls Control.Invoke to marshal the call to the UI thread. But now the UI thread is hung waiting for comReadThread to complete and comReadThread will complete only if Invoke completes, which will only happen if the UI thread is free (i.e not waiting for Join). Clearly, that will not happen and you'll therefore deadlock.
The solution is to either remove the Join or use Control.BeginInvoke instead of Invoke . With BeginInvoke however, it's possible that the delegate will run after the form has closed, so you would have to take care of that condition.
|
|
|
|
|
hi,
I'm a totally new on c# and i wouldn't get this to work now, but I'm very curios if this could work and i could really need it.
I have a notebook with touchpad and when writing i always touch the pad.
because the notebook has no option to deactivate it by a key, i thought if its possible to write an application to do this.
i thought about something that filters all data that comes from the pad, i guess thats on some usb or com-port and leave that data to nowhere while the app is active.
is this possible?
would it work like i said or do you have to use another method?
aaaannnd
if its possible, would anyone be so kind to write me that lil app?
i thought about the app resting in the infopart of the taskbar and you simply left-click it.
one click to activate and another to deactive.
many thanks!
|
|
|
|
|
I think....
jiaoyamin
|
|
|
|