I have tried numerous attempts to fix this problem or bug, firstly by deleting the .tbd files from C:\Users\\AppData\Local\Microsoft\VisualStudio\x.0
I have also tried this:
Visual Studio "Tools" menu
"Options" submenu
"Windows Form Designer" tab
"General" tab
Set "AutoToolboxPopulate" to "True"
The ToolBox list is still not populating correctly and the "BackgroundWorker" component I need is grayed out. Any ideas?
At least a workaround: declare the BackgroundWorker in code, but don't forget to dispose it properly:
public class MyForm : Form
{
private BackgroundWorker bgWorker = null;
public MyForm()
{
InitializeComponent();
this.bgWorker = new BackgroundWorker; //TODO: set properties and event handlers
}
public override void Dispose(bool disposing)
{
//TODO: copy from MyForm.Designer.cs and add:
Backgroundworker bgw = this.bgWorker;
this.bgWorker = null;
if (disposing && bgw != null)
{
try
{
//TODO: release event handlers
bgw.Dispose();
}
catch(Exception)
{
/* consumed disposal error */
}
}
}
}
I have found a solution to my problem, using the BackgroundWorker class in C# without using the component from the toolbox. In this case, I needed two seperate backgroundWorkers:
using System.Threading;
public partial class MainWindow : Window
{
private BackgroundWorker bw1 = new BackgroundWorker();
private BackgroundWorker bw2 = new BackgroundWorker();
public MainWindow()
{
InitializeComponent();
bw1.WorkerReportsProgress = true;
bw1.DoWork += new DoWorkEventHandler(bw1_DoWork);
bw1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw1_RunWorkerCompleted);
bw1.ProgressChanged += new ProgressChangedEventHandler(bw1_ProgressChanged);
bw2.WorkerReportsProgress = true;
bw2.DoWork += new DoWorkEventHandler(bw2_DoWork2);
bw2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw2_RunWorkerCompleted);
bw2.ProgressChanged += new ProgressChangedEventHandler(bw1_ProgressChanged);
}
private void bw1_DoWork(object sender, DoWorkEventArgs e)
{
StatsProcessor proc = new StatsProcessor();
proc.CompareStats(listText1, listText2);
}
private void bw2_DoWork2(object sender, DoWorkEventArgs e)
{
StatsParser parser = new StatsParser();
}
private void bw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressBar2.IsIndeterminate = false;
progressBar2.Value = 100;
btnCompareStats.IsEnabled = true;
}
private void bw2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressBar1.IsIndeterminate = false;
progressBar1.Value = 100;
btnFetchStats.IsEnabled = true;
}
private void bw1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar2.Value = e.ProgressPercentage;
}
private void bw2_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar1.Value = e.ProgressPercentage;
}
private void btnCompare_Click(object sender, EventArgs e)
{
btnCompareStats.IsEnabled = false;
StatsProcessor proc = new StatsProcessor();
if (bw1.IsBusy != true)
{
progressBar2.IsIndeterminate = true;
// Start the asynchronous operation.
bw1.RunWorkerAsync();
}
}
private void btnFetchStats_Click(object sender, RoutedEventArgs e)
{
btnFetchStats.IsEnabled = false;
if (bw2.IsBusy != true)
{
progressBar1.IsIndeterminate = true;
// Start the asynchronous operation.
bw2.RunWorkerAsync();
}
}
}
I would try resetting the toolbox items. Then use the Add Item dialog to put back something you need.
Related
So i have a small xamarin project. Just a little stopwatch:
public partial class Stopwatch : ContentPage
{
Stopwatch stopwatch;
public Stopwatch()
{
InitializeComponent();
stopwatch = new Stopwatch();
labeltimer.Text = "00:00:00.00";
}
private void btnTimerReset(object sender, EventArgs e)
{
btnStart.Text = "Start";
stopwatch.Reset();
}
private void btnTimerstop(object sender, EventArgs e)
{
if (labeltimer.Text != "00:00:00.00")
btnStart.Text = "Resume";
stopwatch.Stop();
}
private void btnTimerStart(object sender, EventArgs e)
{
Timerstart();
}
private void Timerstart()
{
stopwatch.Start();
Device.StartTimer(TimeSpan.FromMilliseconds(1), () =>
{
labeltimer.Text = stopwatch.Elapsed.ToString("hh\\:mm\\:ss\\.ff");
return true; // return true to repeat counting, false to stop timer
});
}
}
}
My problem is now, that everything works perfectly, until i start the stopwatch and lock my phone. The stopwatch then works very slow.
Any idea, how to fix that?
![Server][1]
Code Server :
public partial class Form1 : Form
{
private TcpClient tcpclient;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IPAddress[] localip = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress address in localip)
{
if (address.AddressFamily == AddressFamily.InterNetwork)
{
textBox1.Text = address.ToString();
textBox2.Text = "8888";
}
}
}
private void button1_Click(object sender, EventArgs e)
{
TcpListener listenner = new TcpListener(IPAddress.Any, int.Parse(textBox2.Text));
listenner.Start();
tcpclient = listenner.AcceptTcpClient();
}
![client][2]
Code Client
namespace CLIENT
{
public partial class Form1 : Form
{
private TcpClient tcpclient;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
labelmessage.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
tcpclient = new TcpClient();
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(textBox1.Text), int.Parse(textBox2.Text));
try
{
tcpclient.Connect(ipe);
if (tcpclient.Connected)
{
labelmessage.Visible = true;
labelmessage.Text = "Conected...";
}
}
catch
{
}
}
}
}
Use the TCPClient instance returned by the AcceptTCPClient() method.
TCPClient _client = _listener.AcceptTCPClient();
// Add to listview here for connection
Console.WriteLine(String.Format("{0} connected", _client.Client.RemoteEndPoint.ToString()));
// Same for others
UPDATE
TCPClient _client = _listener.AcceptTCPClient();
ListViewItem _item = new ListViewItem(_client.Client.RemoteEndPoint.ToString());
listview1.Items.Add(_item);
More on working with ListView Controls
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.aspx
i need to take a picture from the directory of Windows phone in my application so i add a child Windows when i click on the text in this child Windows i add a button and i called
public partial class AnnotationControl : ChildWindow
{
public ObservableCollection<string> cercle { get; set; }
public AnnotationControl()
{
InitializeComponent();
}
private void ChildWindow_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void btnsave_Click_1(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void btnCancel_Click_1(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void browse_Click(object sender, RoutedEventArgs e)
{
PhotoChooserTask objPhotoChooser = new PhotoChooserTask();
objPhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooseCall);
objPhotoChooser.Show();
}
but when i clicked on the button to choose a picture the application crashed
"Application_UnhandledException"
some one have any idea please
Use this may be helpful
private void changeImage(object sender, RoutedEventArgs e)
{
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
photoChooserTask.Show();
}
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
imageTapped.Source = bmp;
}
}
How to get the slideshow of images with time interval of 2 seconds. I had referred the below code from stackoverflow but while running iam nt getting any images displayed.. Please tel where iam went wrong...
Xaml:
<image Name=myImg Source={Binding bi}/>
Code:
private DispatcherTimer tmr = new DispatcherTimer();
private List<string> images = new List<string>();
private int imageIndex = 0;
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
tmr.Interval = TimeSpan.FromSeconds(5);
tmr.Tick += new EventHandler(tmr_Tick);
LoadImages();
ShowNextImage();
}
private void LoadImages()
{
// list the files (includede in the XAP file) here
images.Add("/images/filename1.jpg");
images.Add("/images/filename2.jpg");
images.Add("/images/filename3.jpg");
images.Add("/images/filename4.jpg");
}
private void ShowNextImage()
{
Imagesource bi = new BitmapImage(new Uri(images[imageIndex], UriKind.Relative));
myImg.Source = bi;
imageIndex = (imageIndex + 1) % images.Count;
}
void tmr_Tick(object sender, EventArgs e)
{
ShowNextImage();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (!tmr.IsEnabled)
{
tmr.Start();
}
base.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
tmr.Stop();
base.OnNavigatedFrom(e);
}
Thanks in Advance
Change Name=myImg to x:Name="myImg" and remove the Source attribute entirely. Otherwise it looks like it should work.
I'm working on a WP7 application and I need it to play the song in the first link if the current event on the calendar is "Meeting". However, with the current code, it plays the second song instead if the first one even though the event is set correctly.
Here is my code:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Set the data context of the listbox control to the sample data
DataContext = App.ViewModel;
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
// Load data for the ViewModel Items
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Appointments appts = new Appointments();
//Identify the method that runs after the asynchronous search completes.
appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
DateTime start = DateTime.Now;
DateTime end = DateTime.Now;
int max = 1;
//Start the asynchronous search.
appts.SearchAsync(start, end, max, "Appointments Test #1");
textBlock3.Text = DateTime.Now.ToString("hh:mm:ss tt");
}
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
{
try
{
AppointmentResultsDataLINQ.DataContext =
from Appointment appt in e.Results
where appt.IsAllDayEvent == false
select appt;
}
catch (System.Exception)
{
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if ((AppointmentResultsDataLINQ.DataContext).Equals("Meeting"))
{
mediaElement1.Source = new Uri("http://www.opendrive.com/files/NV8zNTMwNDYwX2hxRXZR/Crystallize.mp3", UriKind.Absolute);
}
else
{
mediaElement1.Source = new Uri("https://www.opendrive.com/files/NV8zMjAxODY0X0VBNDJY/Hetken%20tie%20on%20kevyt%20(piano%20cover)%20-%20YouTube.mp3", UriKind.Absolute);
}
mediaElement1.Play();
}
}
The problem appears to be this line:
if ((AppointmentResultsDataLINQ.DataContext).Equals("Meeting"))
You're comparing the result of calling the ToString() method on the Appointment instance with the string "Meeting".
You probably want:
if ((AppointmentResultsDataLINQ.DataContext as Appointment).Subject.Equals("Meeting"))
Update
You're actually checking an Enumerable of Appointments.
Here's how to check if any of them are "Meeting":
if ((AppointmentResultsDataLINQ.DataContext as IEnumerable<Appointment>).Any(app => app.Subject.Equals("Meeting")))