|
SerialPortEvent is executed on the UI thread. So SwipeMethod will run on that same thread.
Not sure on the ShowDialog vs Show deal... but I haven't had very much coffee today
My worker thread/queue setup was based on the assumption you were processing bunches of data from a serial port. If you are popping a form with "Swipe CC now" then it might be worth looking at just using Delegate.BeginInvoke and IAsyncResult. This will use a thread from the pool.
|
|
|
|
|
Yes, I've been playing around some. I'm not sure if it's a bug in .NET 2.0. After the transaction is approved, I want to exit the Form with "this.Close()" but it locks the app. If I switch to BeginInvoke it works ok. Also, I can use Invoke, if I open the form with ShowDialog instead of Show.
Useful link:
avoid invoke
Ron
|
|
|
|
|
hi guys,
i have developed an application that will convert every image file in selected folder to .png and scale images to some specified sizes with checking which one is best. Those sizes are 64 128 256 512 1024 2048. The app checks which is nearest size to scale. For instance, if image dimension is (65 x 125) then it will scale it to 64 x 128 because 65 is nearest to 64 than 128 and 125 is nearest to 128 than 64 and so on...so to this i have coded the app like this :
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
Xal.Clear();
getDirs(fbd.SelectedPath);
string[] tmp_filePaths = (string[])Xal.ToArray(typeof(string));
for (int a = 0; a < tmp_filePaths.Length; a++)
{
if (!tmp_filePaths[a].EndsWith(".txt"))
{
Image tmp_image = Image.FromFile(tmp_filePaths[a]);
int newwidth = roundToNearestPixel(tmp_image.Width);
int newheight = roundToNearestPixel(tmp_image.Height);
Bitmap tmp_bmp = new Bitmap(newwidth, newheight);
Graphics tmp_gra = Graphics.FromImage(tmp_bmp);
tmp_gra.DrawImage(tmp_image, 0, 0, newwidth, newheight);
tmp_bmp.Save(@"D:\texts\" + Path.GetFileNameWithoutExtension(tmp_filePaths[a]) + ".png", System.Drawing.Imaging.ImageFormat.Png);
tmp_gra.Dispose();
}
}
}
}
short[] dimensions = new short[] { 64, 128, 256, 512, 1024, 2048, 4096 };
int roundToNearestPixel(int value)
{
int result;
if (value <= 64)
{
result = 64;
return result;
}
int pointer = 0;
for (int a = 0; a < dimensions.Length; a++)
{
if (dimensions[a] >= value)
{
pointer = a;
break;
}
}
int shortdistance = value - dimensions[pointer - 1];
int largedistance = dimensions[pointer] - value;
if (shortdistance < largedistance)
result = dimensions[pointer - 1];
else
result = dimensions[pointer];
return result;
}
now its doing what i needed but it gives an error as well that is out of memory after every 174 images, i have commented that line. So can anybody tell me how to solve this ?
thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Image,Graphics and Bitmap has a Dispose method which has to be called after using. GDI classes are making unmanaged code extensively. Wrap above said classes usage into using blocks which ensures Dispose call.
if (!tmp_filePaths[a].EndsWith(".txt"))
{
using (Image tmp_image = Image.FromFile(tmp_filePaths[a]))
{
int newwidth = roundToNearestPixel(tmp_image.Width);
int newheight = roundToNearestPixel(tmp_image.Height);
using (Bitmap tmp_bmp = new Bitmap(newwidth, newheight))
using (Graphics tmp_gra = Graphics.FromImage(tmp_bmp))
{
tmp_gra.DrawImage(tmp_image, 0, 0, newwidth, newheight);
tmp_bmp.Save(@"D:\texts\" + Path.GetFileNameWithoutExtension(tmp_filePaths[a]) +
".png", System.Drawing.Imaging.ImageFormat.Png);
}
}
} If the image you are loading is too big, I doubt Image class can handle it.
Xmen wrote: Xal.Clear(); // ArrayList
Use a generic List<string>, so you avoid casting.
|
|
|
|
|
oh, i thought just Graphics need to be dispose. No images arnt too big, it will be rare case if anyone need 4096 size
problem persists even after apply using
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Well, try loading the file into a Stream and use Image.FromStream method. Documentation for Image.FromFile says, it throws OutofMemoryException only when
The file does not have a valid image format.
-or-
GDI+ does not support the pixel format of the file. . Make sure your file won't come in any of these categories.
|
|
|
|
|
HAHAHAHA, damn one of them file was a bullshit, its a hml file that is giving error.
thanks man
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen wrote: its a hml file
You have to check the file extension before loading.
|
|
|
|
|
yes i have added that one with txt
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Ha
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Hi all,
i got question here need some information. i'm new in in programming.
could anyone help.
<br />
#include <stdio.h><br />
int main()<br />
{<br />
int a,b,c:<br />
a=5;<br />
b=7;<br />
c=a+b;<br />
printf("%d+%d=%d\n",c,a,b);<br />
return 0;<br />
}<br />
</stdio.h>
Can, anyone help me go through with this. Thanks. in my mind, the answer display on the screen should be "12+5=17". i'm not sure is that correct. Thanks all.
|
|
|
|
|
A good place to start is on the correct message board:
Visual C++[^]
No, the code is not correct. The order of arguments passed to printf()
will yield
12+5=7
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
can you explain why it has to be 12+5=7?
|
|
|
|
|
Looking at your question again, I see what you're getting at...
The printf() function just inserts the variables (converted to
string form) into the formatting placeholder spots. No arithmetic
is done.
So substituting 12, 5, and 7 in "%d+%d=%d" yields "12+5=7".
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Member 4099222 wrote: Thanks. in my mind, the answer display on the screen should be "12+5=17".
This displays 12 + 5 = 7. To get 12+5=17, try printf("%d+%d=%d\n",c,a,c + a);
|
|
|
|
|
Don't you want 5+7=12?
Which would be:
printf("%d+%d=%d\n",a,b,c);
You need to pass the parameters in the order they are in the format.
printf("%d+%d=%d\n",a,b,c);
1 2 3 1 2 3
See it?
[edit] formatting got screwed up [/edit]
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
I need to save orders locally in an XML file and then when connection is available I need to save them to SQL DB. I have built classes for Order and OrderCollection. What is the best way to save them to an XML file so I can later save them to DB? I am thinking of saving them to a DataSet and calling the WriteXml method on it to write to xml file. Afterwards, I can call ReadXml and then write everything to DB. Is this Ok?
Also, do I have to load all orders from file to a DataSet and add a new order and then re-write it or is there another alternative?
|
|
|
|
|
Mark your class as serializable and use XMLSerializer [^] class to serialize it.
|
|
|
|
|
I have used XmlSerializer before. I have one concern though: Do I have to deserialize all objects, add a new one, and then reserialize them? Reason being is because XmlSerializer creates a root node and a few other things so I can not simply append it to the end of the existing file.
|
|
|
|
|
CodingYoshi wrote: Do I have to deserialize all objects, add a new one, and then reserialize them?
Yeah, that's the better option. If you know how XML serializer is creating nodes, you can use normal XML manipulation classes and append new node to it. But the former option is more easy.
|
|
|
|
|
|
I am just starting to learn the FTPWebRequest and using my work server as testing. I can get the files, download the files and everything. What I was wanting to do is get a directory image and a file image. Using a tree view I want to put the directory image next to the name of the "file" if it was a directory and the same thing for a file except a different image..
I do not see anything or have seen anything that specifies rather it is a directory or a file other than just seeing if it has an extension at the end. How exactly would I do this? Or point me to a tutorial that does do this...
Thanks in advanced!
|
|
|
|
|
I ran a quick test and this seemed to work for me.
string path = "c:\\documents and settings\\administrator\\";
bool exists = System.IO.Directory.Exists(path);
MessageBox.Show("This path is a directory: " + exists.ToString());
Using the same code above, but adding a file name to the path variable:
string path = "c:\\documents and settings\\administrator\\somefile.txt";
bool exists = System.IO.Directory.Exists(path);
MessageBox.Show("This path is a directory: " + exists.ToString());
So if you have a string that you are certain contains either a full file name or a directory path, you should be able to determine if it is a directory or not using System.IO.Directory.Exists(path);
|
|
|
|
|
But that won't work on a remote FTP site...
|
|
|
|
|
My mistake, the way you worded it sounded like they had been downloaded already.
|
|
|
|