|
Another alternative is to make it configurable.
It depends on just what it is you're trying to do.
|
|
|
|
|
Yes, but I don't need that level at the moment.
Additionally, making it configurable doesn't allow the compiler to do certain optimizations. For example, checking a const variable which is statically known to be either true or false gives the compiler an opportunity to optimize the check away, and keep only the relevant code (with unreachable code detected warning).
Many thanks to all helpful guys here in CP!
I really appreciate your help.
Know me better
|
|
|
|
|
Then use conditional compilation.
|
|
|
|
|
Hi there,
I am developing a C# program to record voice simultaneously from some microphones.
I need to save(record) audio inputs on some separate memory streams.
I use Visual studio 2005, a Delta 1010-LT soundcard which has 8inputs.
My problem is in two points, let's suppose that we have just two inputs to record from,
then 1st when I try to save two audio input streams on two separate files, just one of them
saves audio & at the same time two audio inputs get mixed together on just one file while the other one
is saved empty! I want to save them separately not mixed!
The 2nd problem is voice that been recorded; While it is mixed of two audio inputs, it has some gaps just
because of switching job of CPU during recording. I believe if the 1st prob get solved then the 2nd one
will be solved automatically.
How should I do that? Is there any Mixer API that can help me?Confused
Thanks in advance Smile
|
|
|
|
|
I'd work on getting one channel to record properly before
worrying about multiple channels.
If you have gaps you're doing something wrong.
How are you getting audio from the sound card?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hello forum
i need to change the font of text in hindi on runtime.For that i need to installs new fonts of hindi langauage to visual studio.
Do i need that??
How can i do that??
Regards
Rahul Adya
modified on Sunday, September 21, 2008 9:37 AM
|
|
|
|
|
Fonts are installed in the OS. Control panel|fonts
|
|
|
|
|
Hi guys
I want to know how to display a picture stored in an attachment field in an Access 2007 database in a Visual C# picture box or more generally exporting a file from an attachment field in access 2007, I searched a lot but couldn't find, Please help.
Thanks.
©2008 NukeWare
|
|
|
|
|
|
hey guys
Im working on a project that connect users to a recording server.
so i have one ocx file that need to be dragged to a from(win froms),
then im using his fucntions (connnecting to the server and so...)
i would like to work with that ocx file on asp .net ...
is there a way to do it ?
|
|
|
|
|
Hello.
I have been creating a simple irc client that connects to a server and sends some simple commands to it
I have also figured out how to retrive data from the server by using streams
The problem is I have to run a never-ending while to keep retriving all the data from the server
I do it like this:
while ((inputLine = reader.ReadLine()) == null)
{
listBox1.Items.Add(reader.ReadLine());
}
The problem is that my form doesent respond (I cant use buttons, and such) since the while is never-ending
Is there any way of adding a event that triggers when there is new data from the server?
Here is my project:
dumpen.dk/include/files/IrcBot.rar
And a bonus question: When connecting to Quakenet and joining a channel it says: 451 Register first
Why is that?
|
|
|
|
|
Casper Hansen wrote: while ((inputLine = reader.ReadLine()) == null)
{
listBox1.Items.Add(reader.ReadLine());
}
Are you sure that logic is correct? You have essentially written this: While the reader is exhausted add the next line to the list box.
This will go into an infinite loop and effectively block your program for eternity, or until you externally kill the process, or until the memory of all those empty items in the list box is exhausted.
|
|
|
|
|
Well no :P
Thats why I ask here since I cant seem to come up with a solution
|
|
|
|
|
Actually, your question was about whether a specific feature was available in a framework. You did not question the logic.
|
|
|
|
|
I would like help with the logic as well or just some other soloution for my problem
|
|
|
|
|
Is this the correct way of using thread?
using System;
using System.Windows.Forms;
namespace mutlithread
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void FakeUIUpdater(string textboxText)
{
UIUpdaterDelegate updateUI = new UIUpdaterDelegate(UpdateUI);
this.Invoke(updateUI, new object[] { textboxText });
}
delegate void UIUpdaterDelegate(string textboxText);
protected void UpdateUI(string textboxText)
{
textBox1.Text = textboxText;
}
private void button1_Click(object sender, EventArgs e)
{
FakeUIUpdater("test");
}
}
}
|
|
|
|
|
I have a form 'frmProgressBar', which is shown as popup using obj.showDialog(). This form has a backgroundworker thread running, which keeps running till the processing in other forms is not compleated. I want to hide this form whenever the main form is minimised and this form is getting hidden also. But the problem is, when the main form is maximized, I want to show the popup form again. I checked !IsDestroyed which returns false, so the backgroundworker thread is still running, but the form on it is not displayed in the foreground. I tried Show(), BringToFront(), TopLayer = True, but nothing seems to work. Any hellp please.It is very urgent.
Thank You,
Prashant
|
|
|
|
|
bool bContinue = true;
public frmProgressBar(string Message)
{
InitializeComponent();
this.ShowInTaskbar = false;
lblMessage.Text = Message ;
backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
}
//This is called when my main window is resized
private void setWindowStateAccordingToMainForm(FormWindowState State)
{
if (this.InvokeRequired)
{
setWindowState d = new setWindowState(setWindowStateAccordingToMainForm);
this.Invoke(d, new object[] { State });
}
else
{
if ((State == FormWindowState.Maximized) || (State == FormWindowState.Normal))
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Show();
}
}
else if (State == FormWindowState.Minimized)
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Hide();
}
}
}
}
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Close();
this.Dispose();
}
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
while (bContinue)
{
}
}
|
|
|
|
|
First, use codeblock formatting for code pieces this large. It helps reading.
If I read this correctly, you seem to set WindowState to Minimized in all cases
if ((State == FormWindowState.Maximized) || (State == FormWindowState.Normal))
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Show();
}
}
else if (State == FormWindowState.Minimized)
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Hide();
}
}
Also if you want the progress-form to follow main form's windowstate, could you simplify the logic and use mainform's events to minimize, normalize etc. the progress-form. For example in main form:
private void MainForm_SizeChanged(object sender, EventArgs e) {
if (this.WindowState == FormWindowState.Normal) {
this.frmProgressBar.WindowState = FormWindowState.Normal;
this.frmProgressBar.BringToFront();
} else if ...
}
Hope this helps,
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi Mika,
Thank you for your reply.
I typed it 'Minimized' in first if. It was my typing mistake.It should have been 'Maximized' instead.
I can't set the frmProgressBar's windowState from frmMain, because frmProgressBar is not a control in form frmMain, but a separate form whose methods (Hide and Show) are exposed through AggGlobals class (class which stores all application level variables and exposes common functionality). So I can't access it through frmMain.
But thank God, at last I got the solution. I set the 'Owner' property of frmProgressBar to frmMain (for that I had to store an instance of frmMain in AppGlobals) and set CheckForIllegalCrossThreadCalls = false in frmProgressBar constructor, and it worked !!! In vs 2003 it used to work without this setting but in vs 2005 MS has added a check for this. If you run it using ctrl + F5 the application run's perfectly fine, but while debugging i.e. F5 it is an issue.
Storing an object of frmMain in AppGlobals is a temporary solution and I think I will have to do this using reflection.
Cheers,
Prashant.
|
|
|
|
|
Glad you got it solved.
I understood that these are two separate forms. However form is just a class whereas other classes so if you want, you can store a reference to another form in main form using a variable that is type of frmProgressBar. This way you could fully control the frmProgressBar from the main form.
For example when showing progressbar, you could have a methods like following in the main form
private frmProgressBar barForm; <-- at form level
private void ShowProgress() {
barForm = new frmProgressBar();
barForm.Show();
...
}
private void UpdateProgress(int percentage) {
barForm.ProgressControl.Value = percentage;
OR PREFERRABLY
barForm.UpdatePercentage(percentage); <--- this method would update any necessary controls in frmProgressBar
...
}
private void EndProgress() {
barForm.Hide();
barForm = null;
...
}
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi all, I have added a bit more description to yesterdays post.Yesterday Mika had given me a solution, but for some reasons I can't do it that way because of some design constraints, and I have to do it this way only.
I have a form 'frmProgressBar', which is shown as popup using objfrmProgressBar.showDialog() from a class AppGlobals (AppGlobals.prpgressbar.show() method). frmProgressBar has a backgroundworker thread running, which keeps running till the processing in other forms is not compleated. I want to hide popup whenever the main form, on which other controls are loaded, is minimised and the popup is getting hidden also. But the problem is, when the main form is maximized, I want to show the popup form again. I checked !IsDestroyed for frmProgressBar which returns false, so the backgroundworker thread is still running, but the popup is not displayed in the foreground, only main form is shown. I tried Show(), BringToFront(), TopLayer = True, but nothing seems to work. Any help please.It is very urgent.
Following is my code :
bool bContinue = true;
public frmProgressBar(string Message)
{
InitializeComponent();
this.ShowInTaskbar = false;
lblMessage.Text = Message ;
backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler (backgroundWorker_RunWorkerCompleted);
}
//This is called when my main window is resized event us fired
private void setWindowStateAccordingToMainForm(FormWindowState State)
{
if (this.InvokeRequired)
{
setWindowState d = new setWindowState(setWindowStateAccordingToMainForm);
this.Invoke(d, new object[] { State });
}
else
{
if ((State == FormWindowState.Maximized) || (State == FormWindowState.Normal))
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Maximized;
BringToFront();
Activate();
}
}
else if (State == FormWindowState.Minimized)
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Hide();
}
}
}
}
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Close();
this.Dispose();
}
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
while (bContinue)
{
}
}
|
|
|
|
|
Few issues to point out:
1. The logic I suggested won't work if you use ShowDialog . This is because the code on the main form will wait until the dialog is closed. So if you want to use that approach, the main form must be in control all the time and frmProgressBar is only showing the current situation.
2. Of course the logic can be turned upside down so that the frmProgressBar is in control.
3. Another thing is owner. Do you specify any owner in Show or ShowDialog ? If not, try adding ShowDialog(this) (or replace this with instance of the mainform if needed.
And again, try to use:
codeblock formatting. It helps reading several lines of code.
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi,
I'm intrigued. If you have shown the progress form with ShowDialog() as your post suggests, how are you minimising the main form? Is it being done programmatically as I can't see how it could be done by user interaction?
I crafted a little test app which has a main form (Form1), a second form (AboutBox1) and a timer set to 5 seconds the function of which is to minimise and restore the main window. Both forms have the ShowInTaskBar property set to true.
If the app is run with about.Show(this) uncommented the two windows minimise and restore properly as a pair which simulates the action you desire in your app.
However try it when the second form is shown via ShowDialog()and you will find that the second form never reappears once it has been minimised.
I'm not sure why this is the case but the solution to your problem may be as simple as starting the progress form with Show rather than ShowDialog. Use the Show(this) version to ensure that the progress form stays on top of the main form.
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
timer1.Interval = 5000;
timer1.Enabled = true;
}
private void Form1_Shown(object sender, EventArgs e) {
AboutBox1 about = new AboutBox1();
about.ShowInTaskbar = true;
}
private void timer1_Tick(object sender, EventArgs e) {
if (this.WindowState != FormWindowState.Normal) {
this.WindowState = FormWindowState.Normal;
} else {
this.WindowState = FormWindowState.Minimized;
}
}
}
Alan.
|
|
|
|
|
Here is how I have implemented the above code:
When I want to show ProgressBar, I create a ProgressBar instance and start a new thread and show ProgressBar using objProgressBar.ShowDialog(). After this a backgroundWorker thread is started and kept running in the ProgressBar, which doe's nothing and just keeps on looping till bContinue (a bool) is false. When I say HideProgressBar() the variable 'bContinue' is set to false and the Progressbar is destroyed.
I have created a thread for running ProgressBar, because the main thread code will keep on working as is, and when I am done with the main thread processing, I will call HideProgressBar() which will destroy ProgressBar form.
These two forms are in separate projects, which are in the same solution file. MainForm is in a project, which is the Shell of my application and is the first form that is going to be loaded. After that, there will be other controls which will be loaded on this form, as and when required. I have used CAB which is provided by Microsoft.Practices.
I can't specify MainForm type in the ProgressBar's constuctor (as MainForm project's output is exe and not lib and the second thing is it would create cyclic reference). I stored the reference to MainForm (this) instance in the AppGlobals file and used this reference for subscribing to the mainForm's resize event using reflection, in the ProgressBar class. and I am getting the events also.
But when I try to set WindowState of ProgressBar, after I get the event of MainForm resized, the effect is not seen in the ProgressBar form. Also, if I click on some other application in taskbar, still the ProgressBar is shown, even if MainForm is minimized (or sometimes MainForm is in painting / hanged situation)
If I try to set Parent in the Progressbar form I get 'Top-level control cannot be added to a control'.
If I set Owner and add CheckForIllegalCrossThreadCalls = false, the problem is solved temporarily but the application starts behaving abnormally, like the main window after the aplication is started is minimised, or if I click on some other tabs in the main window, still the main Window gets minimised. So I think I will have to go with the solution without Owner property.
Could you please suggest a solution for this. Waiting for your reply
|
|
|
|