WPF has nothing to do with the threading solution, FWIW. I've used WPF once, but I've used the WebClient extensively.
I was going to stick exactly what I mentioned (just coalesce it into one invoke). But then I noticed the repetition, as well as the use of DownloadString(), and separated them out.
This version is not tested but should work excepting minor oversights:
public void CheckOnline()
{
String[] Websites = new String[]{website_1.Text,website_2.Text,website_3.Text,website_4.Text};
StatusBar[] StatBars = new StatusBar[]{status_1,status_2,status_3,status_4}
for(int i=0;i<Websites.Length;i++){
String site = Websites[i];
StatusBar statbar = StatBars[i];
String TempFileUse = Path.GetTempFileName();
WebClient useClient = new WebClient();
useClient.DownloadFileCompleted+=(s,e)=>{
Dispatcher.Invoke(()=>{
if(e.Error!=null){
statbar.Foreground = Elysium.AccentBrushes.Red;
statbar.Content = "Not Working";
}
else {
statbar.Foreground = Elysium.AccendBrushes.Green;
statbar.Content = "Working";
}
File.Delete(TempFileUse);
})};
useClient.DownloadFileAsync(site,TempFileUse);
}
}
Basically it just combines each test, since each one simply uses a different status bar and a different website, those are gathered into corresponding arrays. Then the array is iterated over and with each one a new WebClient is created. the DownloadCompleted event is set to the appropriate code to set the color and text, using the EventArgs passed in to determine if an Error occurred, and then delete the temporary file; the WebClient's DownloadFileAsync is then called.
Note that each event handler uses Invoke() with multiple-line arguments (in fact, I use multi-line lambda's more than once).
If CheckOnline itself is running in another thread (why?) then the initialization logic for the arrays will need to be within a similar Invoke lambda.