|
Im trying to make an app, that i can download my mails from my account.
For the test i have 4 mails, total 200kb. When i download the mails, it takes 30 secs.. aprox.. A LOT! and i dont know how to improve the velocity.
Thanks!
The code that i use to download is this:
ns = networkstream from a TCP, buffer 8192.
private string getemailtest2(int indexservidor)
{
StringBuilder resp1 = new StringBuilder();
bool begin = true;
int compa = 8193;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
while (true)
{
byte[] dataaleer = new byte[8192];
if (ns.DataAvailable || begin)
{
int a = ns.Read(dataaleer, 0, 8192);
}
resp1.Append(enc.GetString(dataaleer).Trim('\0'));
if (begin)
{
compa = Int32.Parse(resp1.ToString().Split(' ')[1]);
begin = false;
}
int leng = enc.GetBytes(resp1.ToString()).Length;
if (leng >= compa)
{
if (!ns.DataAvailable)
{
break;
}
}
}
return resp1.ToString();
|
|
|
|
|
Who is responsible for that mess?
Have you checked the CPU activity, say with Task Manager?
if it is high and you don't get real bandwidth, it indicates you are wasting lots of CPU cycles.
Here are some pointers:
1.
Every iteration of the while loop, you create a new buffer (even when no data available); you read data into it, then trim the entire buffer, i.e. you scan all of it to find out it is empty or only partially filled, whereas Read did return the exact length.
2.
Every iteration of the while loop, you perform an enc.GetBytes() on a string that is always growing; however you already know the previous length, and how much got added. IMO you don't need GetBytes at all.
3.
StringBuilder is said to be cheaper than string for a sequence of operations. However, when it needs to grow, it doubles its capacity by allocating a new array and copying all the data; you can create a StringBuilder with a specific initial capacity, reducing/avoiding the need for such copies.
Suggestions:
1.
with ASCII encoding, what would be the difference between the number of bytes received, and the number of characters in the final text?
2.
throw your code away, and start afresh.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Also:
If you call ToString on the StringBuilder in every iteration in the loop, that will force it to allocate a new buffer and copy the data to it when you continue to add data to it. You lose any benefits of using the StringBuilder, the performance gets as bad as using += on a string. So you will have shuffled around several gigabytes of data before you are done reading the 200 kilobytes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi ,
Can we get the query to check whether a particular table exist or not in the database.
|
|
|
|
|
Hi,
for SQL and MySQL there is a SHOW command.
This[^] is one of many Google hits.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
I have a peculiar bug that's got me baffled. I'm working on a C# winform app in VS2005 and I was trying to make one of its menus dynamic (built from data read from a database). Somewhere along the line the new menu items became doubled so I tried to reverse out the code changes. But no matter what I did these new menu items persisted. I've removed all new code. I've deleted the form's resx. I've emptied the obj and bin directories. I've rebooted my PC. I've saved the form's code in a notepad session, the designer code in another notepad session, deleted the form, then recreated it from the two notepad sessions. The find function cannot locate the text of the new menu items, nor does anything reveal itself when stepping through in debug. No trace shows in the IDE designer. Yet somehow when I run the program there they are!
How is this possible? Where is this being persisted? The workaround was to change the parent menu's ID string, so its not urgent ... but I'd still like to understand what's going on.
|
|
|
|
|
Have you checked the content of the database?
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
I can't see anything suspicious in the database. Besides, all access is screened through stored procedures and I never coded for menus to be stored or retreived from the database (just a simple function that returned a list of strings from which the 'magical' menus were built - that code has since been removed).
But just to be sure I took the database offline: the 'magical' menus still appear.
|
|
|
|
|
Without seeing your code, I wouldn't know a definitive answer (I probably wouldn't have one, even after seeing your code either ), but is there any chance that your routine is being called twice?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Nope. I've commented out large swathes of code so that now all that happens is the form's constructor calls InitialiseComponents. I've verified this by stepping through every line in debug. Additionally, while the text of the original menus can be found using the IDE's search function, the text of the 'magical' menus cannot be found.
|
|
|
|
|
Another piece of the puzzle: whatever is bringing back these dynamic menus (that I no longer create but still appear) is happening after the form's Load method has run and before the first time the form's Activate method is run. (This was determined by stepping through the code and looking at the number of submenus listed in the IDE's "Locals" window on the last line of the Load and the first line of the Activate ... 14 submenus had been added between these two points.)
|
|
|
|
|
Okay, I've found the root of the problem. Even though this thread is now old I figure I should post here anyway in case someone gets a similar problem and finds this thread in a Google search. (Don't you just hate googling for a problem and find loads of other people asking the same questions years before and then they stop without telling you what solution they eventually used?)
The third party controls I was using were placing data in Isolated Storage. Specifically (on Vista) ...
AppData
/Local
/IsolatedStorage
/(gibberish)
/(gibberish)
/Url.(gibberish)
/StrongName.(gibberish)
/Files
/SyncfusionToolsStateInfo.bin.
This file had become corrupted. According to the component authors deleting this file should solve the problem (a new version is recreated). However, in my case my Windows set up had become unstable so I reinstalled the whole of Windows instead. Regardless, Isolated Storage is another place to look when you have these kinds of problems.
(I hope this helps somebody, someday.)
|
|
|
|
|
Hi all,
I want to design a barcode template then I can dynamic print config with multi column and multi row in a page. Can you help me!
Thanks
|
|
|
|
|
Samulong,
I assume you are going to be trying to design this in C# and i'm assuming that you have registered with the appropriate body to print these barcodes, am I right in these assumptions?
I haven't actually done much with page layout / printing in C# but if I had to do it, I would guess it is possible to set it up as a report and store the barcodes in the database as images. You can then dynamically populate the report with barcode images and use C# to render the report and print it. You might want to wait for someone with more experience as there is probably a better way.
However, the reason for my post is, normally some label printers (eg Brother) have dll's included that work with the .NET framework and you can print the label directly from your program to the printer. This will make it easier for you or your client, since the barcodes will all come out chopped and ready, rather then having to peel them off an A4 piece of paper. Another advantage is that you don't have to waste time coding page layouts, the dll already has functions and the paper size you choose will be what gets printed.
Dave
|
|
|
|
|
You don't have to register with anyone to print barcodes - or at least you didn't when I was designing industrial barcode printers a few years ago.
You do have to register in order to use Article Numbers (the code shown on products, and held in simple barcodes) in order that they remain unique to a product. There will be a charge for this!
Because of the way barcodes work, it is not a good idea to store them as images, as resizing images may compromise readability. Generating them on the fly at the resolution you need is better (and not too complex when you get your head around it).
Article Number standards body (UK)[^] can probably give you links for your own country.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thanks for insight I will not recommend the storage of barcodes as images anymore lol
Also I was talking about article numbers when I was refering to registration, I was guessing the OP was gonna be using some form of article number for unique barcodes. I will have to research more for the POS system I am trying to build.
Dave
|
|
|
|
|
A barcode doesn't have to have an Article Number - see EAN128 codes which can contain a whole raft full of stuff, with or without an A.N.
If you are building a POS which will use product ANs, be aware there may be legal restrictions on some operations (including the order in which they are done). For example in the UK to change pricing you must:
Raise price on shelf first.
Wait till all customers who might have selected items at the lower price to leave the store.
Raise price on the computer.
Lowering price is simpler:
Lower price on computer.
Lower price on shelf.
Failure to do it this way may result in serious fines for overcharging!
You may have similar restrictions in your country.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
There's an article on CP on how to print barcodes.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi,
I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size.
The picture box is called myPictureBox and has a size of 70,100 at the beginning.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
System.Threading.Thread.Sleep(1000);
}
}
private void zoomOutPicture(int zoomF)
{
int myHeight = 100+zoomF;
int myWith = 70 + (int)Math.Round(zoomF * .7, 0);
System.Drawing.Size test;
test = new System.Drawing.Size(myWith, myHeight);
myPictureBox.Size = test;
}
I have spent the last 3 hours searching with out any luck so any help is greatly apriciated.
Thank you.
|
|
|
|
|
Hi,
I tried your code on my machine .Net 2.0 vs2005 and it seems to work fine. I added a line that refreshes the form so maybe try this and see if the results are any different.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
this.Refresh();
System.Threading.Thread.Sleep(1000);
}
}
Dave
|
|
|
|
|
Hi Dave,
Thanks a lot, that did the trick.
|
|
|
|
|
Try:
myPictureBox.Size = test;
myPictureBox.Refresh();
My failometer has shot off the end of the scale!
I seem to have misplaced my ban button.. no wait... found it!
|
|
|
|
|
you could "solve" it with some Invalidate() or Refresh() calls, but your approach is fundamentally flawed, since you are blocking the GUI thread for the entire duration of this action, making moving, resizing, e.a. impossible.
The correct approach is by using either a separate thread or a timer; since the actions involve Controls, which need to be handled on the main thread anyway, your best option is to start a Windows.Forms.Timer
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi Luc,
I tried the Invalidate() with out luck but the Refresh() is working.
I will look into the timer when I get a bit more time bur for now Refresh() does the trick.
Thank you.
|
|
|
|
|