|
Yes. Putting that inside the loop will start one thread on every iteration.
Abdul Rahman Hamidy wrote: but didnt help
How are you checking that it is not working?
|
|
|
|
|
well, Finish is a control which have progress bar and lables which gets updated on every transaction.
only one progress bar goes others are stop and does nothing.
when the one is finished then another starts. this shows that others are not working.
and at the same if open the access file then records are not in tables.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
i make a program that load a photo to a pictuerbox.
when i cheng the dir of the pictuerbox and try to delete the first one there is an erorr happen(it can not delete the f:\j.jpg becaus it used by another process)
what can i do?
|
|
|
|
|
Fix your code. Hard to say more because you didn't post it.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Bitmap b=new Bitmap(@"d:\s.jpg");
pictuerbox1.Imege=b;
pictuerbox1.Imege.Save(@"d:\c.jpg");
File.Delete(@"s:\s.jpg");<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
|
|
|
sanforjackass wrote: pictuerbox1.Imege.Save(@"d:\c.jpg");
problem is with this line of your code.
you are deleting image but picture box still using it,
that why you getting error.
1 solution - try to set picturebox image to null before deleting it.
OR create bitmap from stream, like
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
PictrureBox.Image=Image.FromStream(fs);
fs.Close();
hope this would help
|
|
|
|
|
it did not work!!
any help?
|
|
|
|
|
What code you had tried, It worked for me.
|
|
|
|
|
i want to delete it
i tryed
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
PictrureBox1.Image=Image.FromStream(fs);
pictuer1.Image.Save(New Dir);
File.Delete(Dir);
fs.Close();
and it did not work
|
|
|
|
|
|
You are not closing the FileStream until after you try to delete the image, Therefore the image is still being used by the FileStream , hence the error message.
Modify your code:
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
PictrureBox1.Image=Image.FromStream(fs);
}
pictuer1.Image.Save(New Dir);
File.Delete(Dir);
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.”
|
|
|
|
|
thanks as you say i only need to close theFileStream
|
|
|
|
|
Hi folks I know there are lots of different free ones out there.
But I wanted to have a go at somthing quick as a learning exercise.
I got as far as the code below, but am having trouble putting found URL's (i.e. 'eachLineValue') from a web page back into the WebRequest.Create(URL)
Do i need some sort of function around this that I can call recursively with different URL's ?
thanks Mark
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace ShoppingDataExtractor
{
public partial class spider : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
string initialURL = "http://www.bestpricedirectory.com.au/";
try
{
WebRequest myRequest = WebRequest.Create(initialURL);
WebResponse myResponse = myRequest.GetResponse();
Response.Write(myResponse);
Stream resStream = myResponse.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
Response.Write(sb.ToString());
Regex r = new Regex(@"href=\""(.*?)\""",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
MatchCollection matches = r.Matches(sb.ToString());
foreach (Match match in matches)
{
Array values = match.Value.ToCharArray();
foreach (System.Char line in values)
{
File.AppendAllText(@"C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/Projects/ShoppingDataExtractor/spider.txt", ({0}) ,line);
sb.ToString();
}
}
myResponse.Close();
resStream.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
}
|
|
|
|
|
manormi1 wrote: Do i need some sort of function around this that I can call recursively with different URL's ?
Yes. That is exactly you need.
|
|
|
|
|
Hello everyone-
I have an imagelist in my application with 6 images, all .png, all 24x24, 32 bits resolution. I am using them in a treeview control. All is well they show up perfectly for a little while but then during the course of me making code changes and compiling they appear to be getting corrupted. After a few compiles / a few hours later the images will begin to show up on the tree view with hatch marks in them. If I click "choose images" on the image list, they show up in the last with hatch marks. A few compiles later or another hour or two goes by, and there are more hatch marks in the image. It appears to be like a gray grid. If I go into the imagelist and delete all the images and re-add them, they show up fine again, but some time goes by and they begin to start showing hatch marks in them. I cannot figure out what I am doing that is causing the images in that list to "corrupt". Any help would be greatly appreciated!
thanks!
EDIT: The imagelist properties is set properly. Depth 32bit, image size 24,24 which is what all of the images are. (And the imagelist "choose images" when you click on an individual image the properties match, 32b, 24x24)
|
|
|
|
|
The ImageList has well documented problems. Google for .net framework imagelist problems. You will get loads of hits and may even find a solution to your problem. I never have found an entirely satisfactory one. The nearest I have got is to convert my images to icons (*.ico) but that doesn't always work.
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.”
|
|
|
|
|
Hi
I have a Windows Forms Application and I have written a piece of code that makes sure that there will always only be one instance of a form open in my MDI app.
My code looks like this:
private static Forms.Employees.EmployeeForm _newEmployeeForm;
public static Forms.Employees.EmployeeForm GetChildInstance()
{
if(_newEmployeeForm == null || _newEmployeeForm.IsDisposed)
{
_newEmployeeForm = new EmployeeForm();
}
return _newEmployeeForm
}
My question is this, How can I make this code generic so that all my forms can inherit this functionality?
Thanks!
Illegal Operation
|
|
|
|
|
|
Illegal Operation wrote: My question is this, How can I make this code generic so that all my forms can inherit this functionality?
You need an easy method to instantiate forms and keep only one instance at a time, right? I'd try something like,
public static class FormsRepository
{
static Dictionary<Type, Form> cache = new Dictionary<Type, Form>();
public static T GetFormInstance<T>() where T : Form, new()
{
Type type = typeof(T);
T form = null;
if (cache.ContainsKey(type))
{
if (cache[type] == null || cache[type].IsDisposed)
cache[type] = new T();
form = (T)cache[type];
}
else
{
form = new T();
cache.Add(type, form);
}
return form;
}
} This code uses a Dictionary to keep the forms that are used. When you need an instance of Form2 , you can write like.
Form2 frm = FormsRepository.GetFormInstance<Form2>();
frm.Show(); Illegal Operation wrote: makes sure that there will always only be one instance of a form open in my MDI app.
If there will be only one instance of forms, why call it MDI?
|
|
|
|
|
Hey,
I learning now to work with processes on the computer, and i wanted to know how can i thake the Process and convert it into the orginal class.
for example
Take a opening IE running, and from the Process getting the IE command
like set website, or get for example a WindowsMediaPlayer that active, and switch the song.
There is a way to do that?
Thanks! Yahav.
Gindi Bar Yahav - Web & Software developer.
|
|
|
|
|
|
WhiteWolf19 wrote: just like the page below
This sounds like a homework assignment.
We are not going to do your homework for you. Try something and ask specific questions about what you don't understand.
only two letters away from being an asset
|
|
|
|
|
Out of interest I googled C# Ascii art - Loads of hits, including articles with code at CodeProject.
Hope that helped.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I have a class which has a dictionary and I don't want to reveal this information to the outside. So I simply made it a private member. I want people to enumerate through my class so I did the following:
public class CustomerCollection : IEnumerable<KeyValuePair<string, Customer>>
{
#region IEnumerable<KeyValuePair<string,Store>> Members
public IEnumerator<KeyValuePair<string, Customer>> GetEnumerator()
{
return this._districts.GetEnumerator();
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return this._districts.GetEnumerator();
}
#endregion
}
This works fine but during enumeration, the client has to write code as below:
foreach (KeyValuePair<string, Customer> c in this._customers) // _customers is an instance of CustomerCollection
{
c.Value.Name = "Whatever";
}
What should I do if I want the client to be able to do this:
foreach (Customer c in this._customers)
{
c.Name = "whatever";
}
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
Have CustomerCollection contain a list of Customer objects
So your code should look something like this.
NOTE: this is not tested and probably wont compile
<code>
public class Customer
{
public string Name{get; set;}
...
}
public class CustomerCollection : CollectionBase
{
public Customer this[int index]{
get{ return innerList[index];}
set{ innerList[index] = value;}
}
public void Add(Customer item){
innerList.Add(item);
}
}
</code>
If you inherit CollectionBase (System.Collections.Specialized i think) you don't to inherit or even implement IEnumerable because CollectionBase does all the dirty work for you.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|