Search Results

Search found 30 results on 2 pages for 'dispatchertimer'.

Page 2/2 | < Previous Page | 1 2 

  • Avoid hourglass mouse cursor when calling a web-service?

    - by BigMoose
    I don't know if this is a general web-services issue or just my specific scenario, which is a WPF application with a DispatcherTimer calling a web-service method. Whenever the timer is called, the mouse cursor automatically changes to an hourglass cursor. The processing of the call is very short and happens every 3 seconds, so the user experience is that every 3 seconds the mouse filckers as an hourglass for a split-second and then goes back to the normal cursor representation. How can I avoid this inconvenience? Thanks.

    Read the article

  • Which method should I use to give the perception the computer is thinking in programming?

    - by Roy
    I want to create a simple game like tic tac toe where the human user is playing against the computer. The computer function takes a couple of milliseconds to run but I would like to make the computer take 5 seconds to make a move. Which method should I use? 1) Create two memory threads. One for the computer and one for the human user. When the computer is taking 5 seconds to imitate thinking, the human user thread is paused for 5 seconds. 2) Disable input devices for 5 seconds using timer or dispatchertimer 3) Any better methods you can think of Thanks!

    Read the article

  • WP7 How to use a Storyboard

    - by Subby
    I wish to stop using the DispatcherTimer to show animations as that is extremely unpredictable. Instead, I want to start using a Storyboard as that is apparently the best and efficient way to animate controls. I have tried searching for Tutorials but have not, unfortunately, stumbled on one yet. Can anyone please advice me where I can begin? For example, "moving an image across the screen" and then "moving many images at the same time whilst rotating them". Any help is highly appreciated.

    Read the article

  • Setting an XAML Window always on top (but no TopMost property)

    - by Brian Scherady
    I am developing an application based on OptiTrack SDK (from NaturalPoint). I need to run the application window as "Always on Top". The window is designed in XAML and is controled in the class "CameraView" but it does not seem to include a "TopMost" property or equivalent. Attached are the code of "CameraView.xaml.cs" and the code of "CameraView.xaml" that are part of OptiTrack SDK (NaturalPoint) called "Single_Camera_CSharp_.NET_3.0". One could expect the class CameraView to contain properties or members to set the position of the window on the screen or to set it to TopMost but as far as searched I found nothing. I wonder what I should do. Thank you, Brian ================ "CameraView.xaml.cs" using System; using System.IO; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using System.Windows.Threading; namespace TestProject { public partial class CameraView { private const int NP_OPTION_OBJECT_COLOR_OPTION = 3; private const int NP_OPTION_VIDEO_TYPE = 48; private const int NP_OPTION_NUMERIC_DISPLAY_ON = 71; private const int NP_OPTION_NUMERIC_DISPLAY_OFF = 72; private const int NP_OPTION_FETCH_RLE = 73; private const int NP_OPTION_FETCH_GRAYSCALE = 74; private const int NP_OPTION_FRAME_DECIMATION = 52; private const int NP_OPTION_INTENSITY = 50; private const int NP_OPTION_SEND_EMPTY_FRAMES = 41; private const int NP_OPTION_THRESHOLD = 5; private const int NP_OPTION_EXPOSURE = 46; private const int NP_OPTION_SEND_FRAME_MASK = 73; private const int NP_OPTION_TEXT_OVERLAY_OPTION = 74; // public delegate void OnCameraViewCreate(CameraView camera); // public static OnCameraViewCreate onCameraViewCreate; private System.Drawing.Bitmap raw = new System.Drawing.Bitmap(353, 288, System.Drawing.Imaging.PixelFormat.Format32bppArgb); private int mFrameCounter; private int mDisplayCounter; private DispatcherTimer timer1 = new DispatcherTimer(); private bool mVideoFrameAvailable = false; private int mNumeric = -1; private bool mGreyscale = false; private bool mOverlay = true; public CameraView() { this.InitializeComponent(); timer1.Interval = new TimeSpan(0, 0, 0, 0, 10); timer1.Tick += new EventHandler(timer1_Tick); } public int Numeric { get { return mNumeric; } set { mNumeric = value % 100; if (mNumeric = 0) { if (Camera != null) Camera.SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, value % 100); } } } private bool CameraRunning = false; private OptiTrack.NPCamera mCamera; public OptiTrack.NPCamera Camera { get { return mCamera; } set { if (mCamera == value) return; //== Don't do anything if you're assigning the same camera == if (mCamera != null) { //== Shut the selected camera down ==<< if (CameraRunning) { CameraRunning = false; mCamera.Stop(); mCamera.FrameAvailable -= FrameAvailable; } } mCamera = value; if (mCamera == null) { mNumeric = -1; } else { serialLabel.Content = "Camera "+mCamera.SerialNumber.ToString(); //mNumeric.ToString(); } } } private void FrameAvailable(OptiTrack.NPCamera Camera) { mFrameCounter++; try { OptiTrack.NPCameraFrame frame = Camera.GetFrame(0); int id = frame.Id; if (CameraRunning) { GetFrameData(Camera, frame); } frame.Free(); } catch (Exception) { int r = 0; r++; } } private void GetFrameData(OptiTrack.NPCamera camera, OptiTrack.NPCameraFrame frame) { BitmapData bmData = raw.LockBits(new System.Drawing.Rectangle(0, 0, raw.Width, raw.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int stride = bmData.Stride; System.IntPtr bufferPtr = bmData.Scan0; unsafe { byte* buffer = (byte*)(void*)bufferPtr; camera.GetFrameImage(frame, bmData.Width, bmData.Height, bmData.Stride, 32, ref buffer[0]); } raw.UnlockBits(bmData); mVideoFrameAvailable = true; } private void timer1_Tick(object sender, EventArgs e) { if (CameraRunning && mVideoFrameAvailable) { mVideoFrameAvailable = false; cameraImage.Source = Img(raw); mDisplayCounter++; } } private System.Windows.Media.ImageSource Img(System.Drawing.Bitmap img) { System.Drawing.Imaging.BitmapData bmData = img.LockBits(new System.Drawing.Rectangle(0, 0, img.Width, img.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); System.Windows.Media.Imaging.BitmapSource bitmap = System.Windows.Media.Imaging.BitmapSource.Create( img.Width, img.Height, 96, 96, PixelFormats.Bgra32, System.Windows.Media.Imaging.BitmapPalettes.WebPalette, bmData.Scan0, bmData.Stride * bmData.Height, bmData.Stride); img.UnlockBits(bmData); return bitmap; } private void startStopButton_Click(object sender, RoutedEventArgs e) { if (CameraRunning) StopCamera(); else StartCamera(); } public void StartCamera() { if (Camera != null) { mFrameCounter = 0; mDisplayCounter = 0; Camera.FrameAvailable += FrameAvailable; Camera.SetOption(NP_OPTION_VIDEO_TYPE, 0); Camera.SetOption(NP_OPTION_FRAME_DECIMATION, 1); Camera.SetOption(NP_OPTION_INTENSITY, 0); Camera.SetOption(NP_OPTION_EXPOSURE, 10); Camera.SetOption(NP_OPTION_THRESHOLD, 50); Camera.SetOption(NP_OPTION_OBJECT_COLOR_OPTION, 0); SetOverlayOption(); SetGreyscaleOption(); timer1.Start(); Camera.Start(); CameraRunning = true; this.Numeric = mNumeric; startStopButton.Content = "Stop Camera"; } } private void SetGreyscaleOption() { if(mGreyscale) Camera.SetOption(NP_OPTION_VIDEO_TYPE, 1); else Camera.SetOption(NP_OPTION_VIDEO_TYPE, 0); } private void SetOverlayOption() { if(mOverlay) Camera.SetOption(NP_OPTION_TEXT_OVERLAY_OPTION, 255); else Camera.SetOption(NP_OPTION_TEXT_OVERLAY_OPTION, 0); } public void StopCamera() { if (Camera != null) { Camera.Stop(); timer1.Stop(); CameraRunning = false; Camera.FrameAvailable -= FrameAvailable; Camera.SetOption(NP_OPTION_NUMERIC_DISPLAY_OFF, 0); startStopButton.Content = "Start Camera"; } } private void greyscaleButton_Click(object sender, RoutedEventArgs e) { if(mGreyscale) mGreyscale = false; else mGreyscale = true; SetGreyscaleOption(); } private void OverlayButton_Click(object sender, RoutedEventArgs e) { if(mOverlay) mOverlay = false; else mOverlay = true; SetOverlayOption(); } private void exposureSlider_ValueChanged(object sender, RoutedEventArgs e) { if (mCamera!=null) { mCamera.SetOption(NP_OPTION_EXPOSURE, (int) this.exposureSlider.Value); } } private void thresholdSlider_ValueChanged(object sender, RoutedEventArgs e) { if (mCamera != null) { mCamera.SetOption(NP_OPTION_THRESHOLD, (int)this.thresholdSlider.Value); } } private void optionsButton_Click(object sender, RoutedEventArgs e) { if (!propertyPanel.IsVisible) propertyPanel.Visibility = Visibility.Visible; else propertyPanel.Visibility = Visibility.Collapsed; } } } ================ "CameraView.xaml"

    Read the article

  • Is this slow WPF TextBlock performance expected?

    - by Ben Schoepke
    Hi, I am doing some benchmarking to determine if I can use WPF for a new product. However, early performance results are disappointing. I made a quick app that uses data binding to display a bunch of random text inside of a list box every 100 ms and it was eating up ~15% CPU. So I made another quick app that skipped the data binding/data template scheme and does nothing but update 10 TextBlocks that are inside of a ListBox every 100 ms (the actual product wouldn't require 100 ms updates, more like 500 ms max, but this is a stress test). I'm still seeing ~10-15% CPU usage. Why is this so high? Is it because of all the garbage strings? Here's the XAML: <Grid> <ListBox x:Name="numericsListBox"> <ListBox.Resources> <Style TargetType="TextBlock"> <Setter Property="FontSize" Value="48"/> <Setter Property="Width" Value="300"/> </Style> </ListBox.Resources> <TextBlock/> <TextBlock/> <TextBlock/> <TextBlock/> <TextBlock/> <TextBlock/> <TextBlock/> <TextBlock/> <TextBlock/> <TextBlock/> </ListBox> </Grid> Here's the code behind: public partial class Window1 : Window { private int _count = 0; public Window1() { InitializeComponent(); } private void OnLoad(object sender, RoutedEventArgs e) { var t = new DispatcherTimer(TimeSpan.FromSeconds(0.1), DispatcherPriority.Normal, UpdateNumerics, Dispatcher); t.Start(); } private void UpdateNumerics(object sender, EventArgs e) { ++_count; foreach (object textBlock in numericsListBox.Items) { var t = textBlock as TextBlock; if (t != null) t.Text = _count.ToString(); } } } Any ideas for a better way to quickly render text? My computer: XP SP3, 2.26 GHz Core 2 Duo, 4 GB RAM, Intel 4500 HD integrated graphics. And that is an order of magnitude beefier than the hardware I'd need to develop for in the real product.

    Read the article

< Previous Page | 1 2