it's my code:
public void pobierzSuchary()
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("http://../michal/suchary.txt"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
ToastPrompt toast = new ToastPrompt
{
Background = new SolidColorBrush(Colors.Green),
Message = "Suchary zostaĆy pobrane"
};
String[] sucharyTab = e.Result.Split('#');
MessageBox.Show(sucharyTab[1]);
..
}
Button runs pobierzSuchary() and is downloading string, I have a problem when I press second time button. Then i see in messagebox older value, but i changed string on server(manually). I have to disable the applications and run again to see new string
This happens because the windows phone automatically caches values for repeat calls.
Just append a random number onto the end of your webclient call
Something like this
Random ran = new Random();
webClient.DownloadStringAsync(new Uri("http://../michal/suchary.txt?ran="+ran.next().toString()));
Related
I'm having an issue with duplicated content from redirected output.
In my forms I have two buttons: Run and Clear.
public partial class BatchRun : Form
{
Process process = new Process();
public BatchRun()
{
InitializeComponent();
}
private void RunBTN_Click(object sender, EventArgs e)
{
//initiate the process
this.process.StartInfo.FileName = sMasterBATname;
this.process.StartInfo.UseShellExecute = false;
this.process.StartInfo.CreateNoWindow = true;
this.process.StartInfo.RedirectStandardOutput = true;
this.process.OutputDataReceived += new DataReceivedEventHandler(StandardOutputHandler);
this.process.StartInfo.RedirectStandardInput = true;
this.process.Start();
this.process.BeginOutputReadLine();
}
public void StandardOutputHandler(object sender, DataReceivedEventArgs outLine)
{
BeginInvoke(new MethodInvoker(() =>
{
Label TestLBL = new Label();
TestLBL.Text = text.TrimStart();
TestLBL.AutoSize = true;
TestLBL.Location = new Point(10, CMDpanel.AutoScrollPosition.Y + CMDpanel.Controls.Count * 20);
CMDpanel.Controls.Add(TestLBL);
CMDpanel.AutoScrollPosition = new Point(10, CMDpanel.Controls.Count * 20);
}));
}
private void ClearBTN_Click(object sender, EventArgs e)
{
CMDpanel.Controls.Clear();
this.process.CancelOutputRead();
this.process.Close();
this.process.Refresh();
}
}
This works great if I want to run process only once i.e. close the forms once process has completed.
However, I need to allow user to rerun the same process or run a new one hence I have added a clear button the clear various controls etc.
The problem I'm having is that after clicking clear button, I want to click run button again without closing which should then run the sMAsterBAT file(CMD).
StandardOutputHandler seems to be including content of the previous run as well as the new one resulting in duplicated labels in my CMDpanel.
Is this stored in some kind of buffer? If so, How do i clear it to allow me a rerun?
Could someone explain why this is happening and how to resolve it please.
Spoke to someone at work who fixed it for me. So easy lol
private void ClearBTN_Click(object sender, EventArgs e)
{
CMDpanel.Controls.Clear();
this.process.CancelOutputRead();
this.process.Close();
this.process.Refresh();
this.process = new Process(); // this line resolved my issue!!
}
}
first the server code is working well
//declare the target list to be the reciver
List<string> list = new List<string>();
//at the first declare that
//then call it/
private void check(double l, double lo)
{
Service1Client client = new Service1Client();
client.pbackCompleted += new EventHandler<pbackCompletedEventArgs>(pResult);
client.pbackAsync(l, lo);
}
private void pResult(object sender, pbackCompletedEventArgs e)
{
list = e.Result.ToList<string>();
}
but in debugging list is still null ?
and the function pResult as it is not here ?
how can i return the list and assign it to my list on the device code?
thanks in advance
Try this directly, it worked for me
{
Service1Client client = new Service1Client();
client.pbackAsync(l, lo);
client.pbackCompleted += pResult;
}
void pResult(object sender, pbackCompletedEventArgs e)
{
list = e.Result.ToList<string>();
}
thanks for all, It works as i write in my problem, so there is no problem from the beginning.
May be its microsoft SDK.
#Hitesh Salian thanks a lot. thanks for your try, At real when it didn't work i tried your answer but didn't work.
then suddenly nothing change and the code worked.
I have a problem with MediaFoundationEncoder
I need to record from input device file in AAC format, I write the following code:
private Timer timer;
private static IWaveIn _waveIn;
private static IWaveProvider _provider;
public void StartRecorder()
{
_waveIn = new WaveInEvent
{
WaveFormat = new WaveFormat(8000, 1)
};
_provider = new WaveInProvider(_waveIn);
_waveIn.DataAvailable += OnDataAvailable;
_waveIn.StartRecording();
//for testing purpose write only first 5 seconds.
timer = new Timer(5000);
timer.Elapsed += (sender, args) => Stop();
timer.Start();
}
private void Stop()
{
timer.Stop();
_waveIn.StopRecording();
_waveIn.Dispose();
_waveIn = null;
var outputFilename = String.Format("D:\\{0:yyy-mm-dd HH-mm-ss}.aac", DateTime.Now);
MediaFoundationEncoder.EncodeToAac(_provider, outputFilename);
_provider = null;
}
Also I tried to use MediaFoundationEncoder.EncodeToWma - BUT the file size continued to grow even after stopping the recording and disposed _waveIn. Timeline in file is corrrect, something writes to file trash bytes.
P.S. Im using the lastet build of NAudio (1.7).
The file size growing indefinitely issue is likely because your input provider never returns 0 from its Read method. I'd recommend you write all your audio to a memory stream and then use that with a RawSourceWaveProvider to form the input to your encoder. (remember to set the MemoryStream position to 0 before encoding)
I have developed a small console application to test EWS StreamingSubscriptions / Notifications. In the past we used Push Notifications but ,in theory, when using StreamingNotifications I should be able to avoid creating a listener http endpoint and all the trouble with it (firewall, etc.).
So, from my local machine; I'm doing this:
static void Main(string[] args)
{
if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["PrimaryLabUserId"]))
{
throw new ArgumentNullException("Please provide a value for PrimaryLabUserId in app.config");
}
_primaryLabUserId = ConfigurationManager.AppSettings["PrimaryLabUserId"];
string ServiceAccountName = ConfigurationManager.AppSettings["ExchangeServiceAccountName"];
string ServiceAccountPassword = ConfigurationManager.AppSettings["ExchangeServiceAccountPassword"];
_service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
_service.Credentials = new WebCredentials(ServiceAccountName, ServiceAccountPassword);
_service.AutodiscoverUrl(_primaryLabUserId, (x) => true);
_ewsUrl = _service.Url.AbsoluteUri;
var _connection = new StreamingSubscriptionConnection(_service, 30);
var sub = SubscribeForStreamingNotifications();
_connection.AddSubscription(sub);
_connection.OnDisconnect +=
new StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnDisconnect);
// set up subscriptions here.
_connection.OnNotificationEvent +=
new StreamingSubscriptionConnection.NotificationEventDelegate(OnNewMail);
_connection.Open();
Console.WriteLine("Listening streaming...");
Console.ReadLine();
}
public static StreamingSubscription SubscribeForStreamingNotifications()
{
var folderIds = new List<FolderId>()
{
WellKnownFolderName.Inbox,
WellKnownFolderName.Calendar
};
var eventTypes = new List<EventType>();
eventTypes.Add(EventType.NewMail);
eventTypes.Add(EventType.Deleted);
eventTypes.Add(EventType.Moved);
eventTypes.Add(EventType.Created);
eventTypes.Add(EventType.Modified);
return _service.SubscribeToStreamingNotifications(folderIds, eventTypes.ToArray());
}
private static void OnNewMail(object sender, NotificationEventArgs args)
{
var test = args;
Console.WriteLine("Incoming");
}
The Subscription initializes OK, but when I send a new mail to the LabUser nothing happens. The Notification Event never fires. I tried the same with pushnotifications and it was working (on another server with a public http endpoint for exchange to call back).
I was wondering if this might have anything to do with my local machine.
How very stupid of me. I forgot to impersonate. Since I'm calling into EWS with a service account it is of course listening on the mailbox of that account unless you specify:
_service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, _primaryLabUserId);
My project is about Remoting and i want to add a webcam component to it. Here it goes: I have 3 project in my solution... Client, Server, Remote.dll. In Remote.dll is a common class which has methods works in server machine. When i call these methods from Client it executes in server side. So now my question is i put the code of Webcam in remote.dll and it has an event called "video_NewFrame" which it works everytime when webcam catch an image. But i cant reach to the images from my Client side because when code drops to this event it executes infinitely
and my timer in Client side doesnt work as well. I tried to assing image to my global variable but whenever code goes to client and comes to Remote.dll again my variable is null...
How can i reach simultaneously captured images from my client? here is my code:
(i use AForge framework for webcam)
private bool DeviceExist = true;
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource = null;
public bool WebCamStart(int DeviceIndex)
{
if (DeviceExist)
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
//string myDevice = videoDevices[0].Name;
videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
CloseVideoSource();
videoSource.DesiredFrameSize = new Size(640, 480);
//videoSource.DesiredFrameRate = 10;
videoSource.Start();
return true;
}
else return false;
}
public Bitmap lastImg;
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
//in executes infinitely when execution comes here and i cant reach from Cliend side...
}
public string getFPS()
{
return videoSource.FramesReceived.ToString();
}
public void CloseVideoSource()
{
if (!(videoSource == null))
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource.Stop();
videoSource = null;
}
}
public string getCamList()
{
string result = "No Device Found";
try
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
//comboBox1.Items.Clear();
if (videoDevices.Count == 0)
throw new ApplicationException();
DeviceExist = true;
foreach (FilterInfo device in videoDevices)
{
//comboBox1.Items.Add(device.Name);
result = device.Name;
return result;
}
//comboBox1.SelectedIndex = 0; //make dafault to first cam
}
catch (ApplicationException)
{
DeviceExist = false;
//comboBox1.Items.Add("No capture device on your system");
return "No capture device on your system";
}
return result;
}
// and my client side...
private void timerWebCam_Tick(object sender, EventArgs e)
{
//lblFPS.Text ="Device Running... " + remObj.getFPS() + " FPS";
pictureBox1.Image = remObj.lastImg;
}