|
That doesn't really offer any more detail.
|
|
|
|
|
Encode your information in a text file on the web, then use tinyurl.com to get an 8-character url reference to it.
|
|
|
|
|
Hi Braniacs
I have a performance optimization problem that has been bothering me for some time. I have tried to squeeze more performance from it without much success.
The system (simplified) is as follows:
1) Requests come in over an HTTP Post (I need to respond syncronously / inline)
2) I process the request, and return a response (all xml)
3) If I do not have a result ready within 15 seconds, I respond with a 'server busy, try later' type message.
As the central message processing mechanism I have used a Task based approach to queue, start and wait for messages (max of 15 seconds)
When a message is processed almost instantanesouly, the throughput (requests per second) is quite good (1000/s). However, when message processing is delayed by 200ms, this
degrades rather badly to 40/s
A few snippets:
public void AddMessage()
{
Task.Factory.StartNew<MessageResponse >(() =>
{
return worker.ProcessMessage(),
,
TaskCreationOptions.None);
}
public MessageResponse GetMessage()
{
task.Task.Wait(15 * 1000);
switch (task.Status)
{
case TaskStatus.Running:
message = "Your request is taking longer than usual"
case TaskStatus.RanToCompletion:
message = (MessageResponse)task.Result;
}
return message;
}
Note:
Task creation options None / Longrunning / PreferFairness has no impact. When running the visual studio performance analyser, I can visually see Longrunning creating a new thread for each request (expected), and None using a limited number (underlying threadpool) to service the requests.
Looking at both ANTS performance profiler and Visual studio Performance analyzer, there are no concurrency issues around contention and no other obvious areas where time is being wasted (either cpu time or wall clock time)
What is clear from the visualized results is that in a situation where say 1000 requests are queued, 90% of the program time is spent on thread servicing and context switching (obviously very expensive). My conclusion is that waiting on the result (over multiple requests) is very costly.
If i doing this on a web page or WPF form I could make it completely asyncronous, however I dont have this option.
Is there any where I can alter the message processing mechanism to optimize concurrency better? I am open to anything really , would even explore async / await if it would benefit.
Thanks in advance
|
|
|
|
|
my main problem is when i add dynamically a progressbar on flowLayoutPanel1 for each request then how can i increase right progressbar value frombackgroundWorker1_ProgressChanged event
when user click on start button then i will call RunWorkerAsync function of background worker....it is fine. here i am writing a sample code and try to show my problem.
my form has one textbox, one button and one flowLayoutPanel1 with FlowDirection topdown.
when user enter any url in textbox and click on start button then i will start file download with BackGroundWorker and add one progress bar dynamically on flowLayoutPanel1. 10 file can be downloaded at a time. so when user enter ten url one after after one and click on submit button then ten file will be downloading in background.
my problem is how to increment 10 progress bar progress properly from backgroundWorker1_ProgressChanged event another issue is when any file download will complete then the progress bar for which it has been created will be removed from panel
here is my full code. please have a look and tell me what i need to do to achieve my task. if anyone see there is problem in my code for which a dead lock may appear then also please guide me how to avoid dead lock. here is my code
public partial class Form1 : Form
{
static int pbCounter = 1;
public Form1()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
ProgressBar pb = new ProgressBar();
if (pbCounter <= 10)
{
pb.Width = txtUrl.Width;
flowLayoutPanel1.Controls.Add(pb);
pbCounter++;
System.ComponentModel.BackgroundWorker backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
backgroundWorker1.RunWorkerAsync();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
System.ComponentModel.BackgroundWorker worker = sender as System.ComponentModel.BackgroundWorker;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else if (e.Cancelled)
{
}
else
{
pbCounter--;
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar1.Value = e.ProgressPercentage;
}
}
tbhattacharjee
|
|
|
|
|
Hi,
I updated your code and it should work, but I didn't test it, so you have to try it out.
public partial class Form1 : Form
{
static int pbCounter = 1;
int counter = 0;
public Form1()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
ProgressBar pb = new ProgressBar();
if (pbCounter <= 10)
{
pb.Tag = counter++;
pb.Width = txtUrl.Width;
flowLayoutPanel1.Controls.Add(pb);
pbCounter++;
System.ComponentModel.BackgroundWorker backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.RunWorkerAsync(counter);
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
System.ComponentModel.BackgroundWorker worker = sender as System.ComponentModel.BackgroundWorker;
worker.ReportProgress(<percentToReport>, e.Argument);
e.Result = e.Argument;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else if (e.Cancelled)
{
}
else
{
pbCounter--;
ProgressBar barToRemove = null;
foreach (object control in flowLayoutPanel1.Controls)
{
ProgressBar bar = control as ProgressBar;
if (bar != null && bar.Tag == e.Result)
{
barToRemove = bar;
break;
}
}
if (barToRemove != null)
{
flowLayoutPanel1.Controls.Remove(barToRemove);
}
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
foreach(object control in flowLayoutPanel1.Controls)
{
ProgressBar bar = control as ProgressBar;
if (bar != null && bar.Tag == e.UserState)
{
bar.Value = e.ProgressPercentage;
break;
}
}
}
}
Hope this helps,
Thomas.
|
|
|
|
|
thanks
tbhattacharjee
|
|
|
|
|
You're welcome
|
|
|
|
|
I've got the following code that did seem to be working successfully: (It's sending a SOAP envelope to a Java web service and receiving a response) EndPoint is just a string property containing the URL and path to the WebService, Response is a HttpWebResponse property, that other classes use to process the response SOAP.
HttpWebRequest req = (HttpWebRequest) WebRequest.CreateDefault(new Uri(EndPoint));
req.ContentType = "text/xml; charset=utf-8";
req.Method = "POST";
req.Accept = "text/xml";
req.KeepAlive = false;
req.Timeout = Timeout;
req.Proxy = WebRequest.GetSystemWebProxy();
req.Headers.Add("SOAPAction", EndPoint);
using (StreamWriter stm = new StreamWriter(req.GetRequestStream(), Encoding.UTF8))
{
stm.Write(soapRequest.ToString(SaveOptions.DisableFormatting));
stm.Flush();
}
Response = null;
try
{
Response = ((HttpWebResponse) req.GetResponse());
using (StreamReader reader = new StreamReader(Response.GetResponseStream(), Encoding.UTF8))
ResponseString = reader.ReadToEnd();
}
catch (WebException we)
{
throw new ApplicationException("A web exception occurred in calling Transact OUG!\r\n" + we.Message, we);
}
catch (Exception e)
{
throw new ApplicationException("A general exception occurred when calling Transact OUG!\r\n" + e.Message, e);
}
finally
{
if (Response != null)
Response.Close();
req = null;
}
Now I'm not sure what's really changed but I'm getting really odd errors like 'An operation was attempted on something that is not a socket', now I think this might be threading related. As I'm seeing the very first time it returns a timeout, its only the second attempts that I get the odder errors.
As I said this code was working fine when it was called via a single Window WPF app, I've since changed the app to be two hosted UserControls. These don't interact and both have separate ViewModels, but they do both call this method at some point (not simultaneously though).
So my question is have I made some silly mistakes in the above code? Is there anything I should be aware of?
|
|
|
|
|
I made a DirectSound recording program, but the sound is too small. How can amplify sound?
|
|
|
|
|
Better make sure that the recording device uses best Volume, and the user keeps the microphone in an apprpriate distance from his mouth.
It is possible to access the audio samples of the recorded file, and to multiply its values by some factor (make sure you do not get higher values than accepatble for oyur sampling depth). But the sound quality will be bad.
|
|
|
|
|
Thank you for your reply! But I'm not very understand! I don't know how to amplify sound, colleagues guarantee quality!
|
|
|
|
|
What Bernhard said was, "Forget amplifying it. If you amplify a bad recording will will only get a louder bad recording". You cannot compensate for bad recording by making it louder. Do the recording correctly and you don't need to worry about it.
You have to multiple the samples by a scaling factor, the result of which cannot exceed the sample range of your recording setup.
|
|
|
|
|
i have these errors and i cant fix them. i use crystal reports in c# visual studio.
1)
Error 4 The type or namespace name 'ReportClass' could not be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\Visual Studio 2010\Projects\version1\WindowsFormsApplication1\WindowsFormsApplication1\CrystalReport1.cs 19 35 WindowsFormsApplication1
2)
Error 1 The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\Visual Studio 2010\Projects\version1\WindowsFormsApplication1\WindowsFormsApplication1\CrystalReport1.cs 14 11 WindowsFormsApplication1
3)
Error 4 The type or namespace name 'ReportClass' could not be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\Visual Studio 2010\Projects\version1\WindowsFormsApplication1\WindowsFormsApplication1\CrystalReport1.cs 19 35 WindowsFormsApplication1
4)
Error 10 The type or namespace name 'ICachedReport' could not be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\Visual Studio 2010\Projects\version1\WindowsFormsApplication1\WindowsFormsApplication1\CrystalReport1.cs 93 52 WindowsFormsApplication1
can you help me pls??
|
|
|
|
|
Make sure you have the right crystal report components installed.
If you use Visual Studio Express, you won't get these components in any case.
|
|
|
|
|
If you have the correct components you need to add them to your project (right click - add reference) and also use them (top of your class using ....;)
|
|
|
|
|
I find the problem ...
i put the choice framework 4 in my properties of visual studio and it stop have a problem..
thanks
|
|
|
|
|
good for you! Nice to hear it works.
|
|
|
|
|
i want to download multiple file and want to show multiple progress bar for each file download progress.i got a code which can download file at a time but i want to start download many files at a time and also like to show progress bar for each file progress
suppose i have one textbox where i will put url and when i click on download button then download will start and a progress bar will be show for showing that file download progress. the same if i put another url in textbox and click on download button then another file download start and another progress bar will be shown to show that file download progress. i want that each file will be downloading in separate thread means my program will be multi threaded.
the code i have for downloading one file at a time.please guide me what to change in code to achieve my goal. thanks
private Queue<string> _downloadUrls = new Queue<string>();
private void downloadFile(IEnumerable<string> urls)
{
foreach (var url in urls)
{
_downloadUrls.Enqueue(url);
}
btnGetDownload.Text = "Downloading...";
btnGetDownload.Enabled = false;
progressBar1.Visible = true;
lblFileName.Visible = true;
DownloadFile();
}
private void DownloadFile()
{
if (_downloadUrls.Any())
{
WebClient client = new WebClient();
client.DownloadProgressChanged += client_DownloadProgressChanged;
client.DownloadFileCompleted += client_DownloadFileCompleted;
var url = _downloadUrls.Dequeue();
string FileName = url.Substring(url.LastIndexOf("/") + 1,
(url.Length - url.LastIndexOf("/") - 1));
client.DownloadFileAsync(new Uri(url), "C:\\Test4\\" + FileName);
lblFileName.Text = url;
return;
}
btnGetDownload.Text = "Download Complete";
}
private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
throw e.Error;
}
if (e.Cancelled)
{
}
DownloadFile();
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
tbhattacharjee
|
|
|
|
|
I want to convert a folder full of screenshots into a movie (.avi file) with a certain frame rate, is this possible?
Say the folder has 48 images and the frame rate is 24 frames per second, that would then result with a 2 second long video.
Also, would it be possible to then add sounds to specific points in the video? Say, play "explosion.wav" after 10 seconds?
NOTE: I am not looking for a program that does this, I know they exist. I want to know how to do this with C# code.
|
|
|
|
|
If you are looking for a simple avi video, this[^] might help.
Yuu will need to use their package.
|
|
|
|
|
Tried to run this program to save a screensaver but it doesnt seem to work.
The screensaver is generated from a form and this portion of the code which is for the "save" button creates an object with 0 bytes.
private void button6_Click(object sender, EventArgs e)
{
saveFileDialog1.FileName = "";
saveFileDialog1.Title = "Images";
saveFileDialog1.Filter = "screensaver.scr(*.scr)|*.scr";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName.ToString() != "")
{
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
pictBox1.ImageLocation = saveFileDialog1.FileName.ToString();
}
savefile.Enabled = true;
}
private void pictBox1_Click(object sender, EventArgs e)
{
}
}
|
|
|
|
|
Where is the save operation?
Use the best guess
|
|
|
|
|
What do you mean by "save a screensaver"??
Your code doesn't make any sense at all. You're letting the user pick a ".SCR" file, which is the extension used by screen saver executable files. Then you're trying to display the contents of that file in a picturebox?? WHAT?? You can't do that as a .SCR file is EXECUTABLE, NOT IMAGE DATA!
And, a little pet peeve of mine ... You're calling .ToString() on the FileName property. FileName returns A STRING, so why are you calling .ToString on a String???
|
|
|
|
|
Dave Kreskowiak wrote: why are you calling .ToString on a String? Pet peeve of mine also; it is amazing how many people do it.
Use the best guess
|
|
|
|
|
I write 2 functions in C# to control the progress in a C++ function, using callback
public partial class HjCalibrateForm : Form
{
public static ProgressForm pro_form;
static void progress_init(int max)
{
pro_form = new ProgressForm();
pro_form.Show();
pro_form.progressBar1.Minimum = 0;
pro_form.progressBar1.Maximum = max;
}
static void setValue( )
{
pro_form.progressBar1.Step = 1;
pro_form.progressBar1.PerformStep();
if (pro_form.progressBar1.Value == pro_form.progressBar1.Maximum)
pro_form.Dispose();
}
}
Then in C++,callback
progress_init(max)
for(int i=0;i<max;i++)
{
……set_value();
}
it runs well when i Debug it, but if i excute it directly. It will fail(just stuck). No error message.
It may be something about the Thread, but i can't get it.
modified 27-Mar-13 23:00pm.
|
|
|
|