Hi All,
When thread returns, that means the thread is closed ?
What is the standard way to kill it ?
threadA= null ;
Thank you for advice!
/* CODE BEGIN */
public partial class Form1 : Form
{
private static Thread thread_Interent ;
...
public void Boki_internet_C allbackFunction ()
{
{
// code a b c d e g g
Thread.Sleep(10 00);
}
}
....
}
/* CODE END */
Best regards,
Boki. 5 1467
On Jul 9, 2:35 pm, Boki <bokit...@ms21. hinet.netwrote:
Hi All,
When thread returns, that means the thread is closed ?
What is the standard way to kill it ?
threadA= null ;
Thank you for advice!
/* CODE BEGIN */
public partial class Form1 : Form
{
private static Thread thread_Interent ;
...
public void Boki_internet_C allbackFunction ()
{
{
// code a b c d e g g
Thread.Sleep(10 00);
}
}
...
}
/* CODE END */
Best regards,
Boki.
My issue is, my form is running, user needs to type some text in a
textbox, and the thread is downloading data from internet by this
line:
pictureBox1.Ima ge = new System.Drawing. Bitmap(new
System.IO.Memor yStream(new
System.Net.WebC lient().Downloa dData(picStr))) ;
if there is no thread, program will be completely block until the
picture was loaded.
so, I only need this thread starting work when I need it to load a
picture.
Could you please advice any idea ?
Thanks a lot!
Best regards,
Boki.
How about:
pictureBox1.Loa dAsync(url);
The best way of stopping a thread is to let it exit cleanly, possibly
getting it to short-circuit internally by toggling a flag or whatver
(to break from a loop). Setting a varible (to the thread) to null
doesn't impact the thread in the least.
In the more general sense, when working with forms you can use
pool-threads to perform background activities, e.g.
void StartLoadImage( string url) {
// runs on UI thread when method invoked
ThreadPool.Queu eUserWorkItem(d elegate {
// runs on background thread
using(WebClient webClient = new WebClient())
using(MemoryStr eam stream = new
MemoryStream(we bClient.Downloa dData(url))) {
this.Invoke((Me thodInvoker)del egate { // not
BeginInvoke, else stream might Dispose()
// runs on UI thread when data is available
pictureBox1.Ima ge = new Bitmap(stream);
});
}
});
}
You can also use async-callbacks, but I find the above easier to
read... but it doesn't take advantage of completion ports, etc...
Marc
On Mon, 09 Jul 2007 00:21:22 -0700, Marc Gravell <ma**********@g mail.com
wrote:
[...]
this.Invoke((Me thodInvoker)del egate { // not
BeginInvoke, else stream might Dispose()
// runs on UI thread when data is available
pictureBox1.Ima ge = new Bitmap(stream);
});
Maybe I'm missing something, but why not just create the Bitmap from the
Stream in the background delegate, instead of passing the Stream to the UI
delegate to be used to construct the Bitmap? Then you're not tied to
Invoke() versus BeginInvoke().
Pete
why not just create the Bitmap from the Stream in the background delegate
Looking at it again, I can't think of any reason not to... I guess it
didn't occur to me at the time (it was a hasty example, to show the
general case, given that LoadAsync exists).
For the OP's benefit, this would look like:
....
Bitmap bmp = new Bitmap(stream);
this.BeginInvok e((MethodInvoke r) delegate {
// runs on UI thread when data is available
pictureBox1.Ima ge = bmp;
}
Marc
On Mon, 09 Jul 2007 21:00:20 -0700, Marc Gravell <ma**********@g mail.com
wrote:
For the OP's benefit, this would look like:
Or (just to be complete):
....
Bitmap bmp = new Bitmap(stream);
this.Invoke((Me thodInvoker) delegate {
// runs on UI thread when data is available
pictureBox1.Ima ge = bmp;
}
:)
Pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Greg |
last post by:
I am teaching myself visual basic .net 2003. I bought a book and worked the
examples, but I cannot figure out what I am doing wrong on my first
application.
I have a form that is called from a module:
frmSelectGroup.ShowDialog()
This works fine and the form opens. On the form, the user is asked to
select some options and then click "Continue". When the "Continue" button
|
by: bill |
last post by:
I am confused by the behavior of the following code. The function
copy() takes two FILE *'s and copies the data from one to the other.
In the main routine, I create a pipe and copy stdin to the write end
while copying the read end to stdout. If the child handles copying the
read end of the pipe to stdout, the main program returns. If the child
handles copying stdin to the write end of the pipe, the parent hangs in
copy(), blocking on...
|
by: tshad |
last post by:
This is from my previous post, but a different issue.
I have the following Javascript routine that opens a popup page, but doesn't
seem to work if called from an asp.net button. It seems to work fine from a
link.
The button does bring up the popup window, but when I press the links on the
page, it doesn't return or close the window.
****************************************************************************
|
by: henk |
last post by:
Hi,
I want to show a message in my vb.net program when another windows
program (eg calc.exe) is stopped by a user.
with
pList = myProcess.GetProcesses
For Each myProcess In pList
I can check if the program/process is running.
I could use a timer or run the check on every control event, but what I
|
by: Tom |
last post by:
How is the best way to avoid validation when closing a
window? For instance, I have a Windows Forms window which
has a validation event for a text box. However, if one
enters invalid data in then and then attempts to close the
window (either via my custom 'Close' box or by clicking the
close 'X' in the upper right window corner), the validation
event still triggers and it tells the user that they have
invalid data. Which of course means...
| |
by: alistair_henderson |
last post by:
Morning All,
I have some code for a website which uses 'window.open' to simulate
modal dialog boxes. I use the window.closed property to decide if the
window object exists at various points. This has been fine until last
week when I started getting javascript 'Permission Denied' errors when
I try to access this property.
I suspect that a windows update has caused this somehow, as this code
has not changed for a very long time. Can...
|
by: semedao |
last post by:
Hi , I am using asyc sockets p2p connection between 2 clients.
when I debug step by step the both sides , i'ts work ok.
when I run it , in somepoint (same location in the code)
when I want to receive 5 bytes buffer , I call the BeginReceive and then
wait on AsyncWaitHandle.WaitOne()
but it is signald imidiatly , and the next call to EndReceive return zero
bytes length , also the buffer is empty.
here is the code:
public static byte...
|
by: Edwin Smith |
last post by:
I have a form which displays a DataGridView table generated with the VS2005
tools. The database is a Pervasive v.9 with an ODBC driver.
The DataGridView works great except when I'm done and I click the X to close
the form the .exe refuses to die and has to be killed in Task manager.
I ran a debug trace and it seems to work fine. I dropped a CLOSE button onto
the form and put "this.Close();" in for it's event but I get the same
result.
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hi I tried a google search but could not find anything. I am trying to cause
one webpage to reload when a second web page is closed. The second webpage
loads data into a session variable and when closed I need to reload the first
page loading in the data from the session variable. Since I need to close
the sescond form just setting the post back url to the first page on the
close button from the second page is not quite what I am looking...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |