本文整理汇总了C#中Windows.System.Threading.ThreadPoolTimer类的典型用法代码示例。如果您正苦于以下问题:C# ThreadPoolTimer类的具体用法?C# ThreadPoolTimer怎么用?C# ThreadPoolTimer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThreadPoolTimer类属于Windows.System.Threading命名空间,在下文中一共展示了ThreadPoolTimer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: UCSensor
//private void LedTest()
//{
// var led = new Led(22);
// led.On();
// led.Off();
//}
private void UCSensor()
{
this.InitGpio();
_animation = new BlinkAnimation(_led1, _led2);
_animation.Start();
_timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(500));
}
开发者ID:CaptainBart,项目名称:Windows.Devices.Gpio.Components,代码行数:14,代码来源:StartupTask.cs
示例2: PeriodicTimerCallback
//
// Simulate the background task activity.
//
private void PeriodicTimerCallback(ThreadPoolTimer timer)
{
if ((_cancelRequested == false) && (_progress < 100))
{
_progress += 10;
_taskInstance.Progress = _progress;
}
else
{
_periodicTimer.Cancel();
var key = _taskInstance.Task.Name;
//
// Record that this background task ran.
//
String taskStatus = (_progress < 100) ? "Canceled with reason: " + _cancelReason.ToString() : "Completed";
BackgroundTaskSample.TaskStatuses[key] = taskStatus;
Debug.WriteLine("Background " + _taskInstance.Task.Name + taskStatus);
//
// Indicate that the background task has completed.
//
_deferral.Complete();
}
}
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:29,代码来源:BackgroundActivity.cs
示例3: button_Click
private void button_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("StartButton thread id: " + Environment.CurrentManagedThreadId);
TimeSpan period = TimeSpan.FromSeconds(1);
PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(ElapsedHander, period, DestroyedHandler);
}
开发者ID:karppa1,项目名称:Demo1,代码行数:7,代码来源:MainPage.xaml.cs
示例4: Run
public async void Run(IBackgroundTaskInstance taskInstance)
{
// Ensure our background task remains running
taskDeferral = taskInstance.GetDeferral();
// Mutex will be used to ensure only one thread at a time is talking to the shield / isolated storage
mutex = new Mutex(false, mutexId);
// Initialize ConnectTheDots Settings
localSettings.ServicebusNamespace = "windowactuator-ns";
localSettings.EventHubName = "ehdevices";
localSettings.KeyName = "D1";
localSettings.Key = "1uMOwjURpgGX9l5JqnYeatBkIRoLzP7qH8YGFUeAIrU=";
localSettings.DisplayName = GetHostName();
localSettings.Organization = "Ulster University";
localSettings.Location = "North Europe";
SaveSettings();
// Initialize WeatherShield
await shield.BeginAsync();
// Create a timer-initiated ThreadPool task to read data from I2C
i2cTimer = ThreadPoolTimer.CreatePeriodicTimer(PopulateWeatherData, TimeSpan.FromSeconds(i2cReadIntervalSeconds));
// Start the server
server = new HttpServer(port);
var asyncAction = ThreadPool.RunAsync((w) => { server.StartServer(shield, weatherData); });
// Task cancellation handler, release our deferral there
taskInstance.Canceled += OnCanceled;
// Create a timer-initiated ThreadPool task to renew SAS token regularly
SasTokenRenewTimer = ThreadPoolTimer.CreatePeriodicTimer(RenewSasToken, TimeSpan.FromMinutes(15));
}
开发者ID:scisjg,项目名称:IoT_Actuator,代码行数:35,代码来源:StartupTask.cs
示例5: Run
public void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
Init();
temperatureTimer = ThreadPoolTimer.CreatePeriodicTimer(temperatureTimer_Tick, TimeSpan.FromMinutes(5));
thermostatStatusTimer = ThreadPoolTimer.CreatePeriodicTimer(thermostatStatusTimer_Tick, TimeSpan.FromMilliseconds(500));
}
开发者ID:adgroc,项目名称:win-iot-core,代码行数:7,代码来源:StartupTask.cs
示例6: Page_Loaded
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
ftManager = new FTManager();
timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(500));
await seClient.Connect();
}
开发者ID:jklemmack,项目名称:IoTIrrigationController,代码行数:7,代码来源:MainPage.xaml.cs
示例7: Timer_Tick
private void Timer_Tick(ThreadPoolTimer timer)
{
try
{
var devicesList = ftManager.GetDeviceList();
Debug.WriteLine(devicesList.Count);
if (devicesList.Count > 0)
{
timer.Cancel();
var infoNode = devicesList[0];
IFTDevice ftDevice = ftManager.OpenByDeviceID(infoNode.DeviceId);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
ftDevice.SetBaudRateAsync(9600);
ftDevice.SetDataCharacteristicsAsync(WORD_LENGTH.BITS_8, STOP_BITS.BITS_1, PARITY.NONE);
ftDevice.SetFlowControlAsync(FLOW_CONTROL.NONE, 0x00, 0x00);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
device = new XBeeDevice(ftDevice);
ListenForData();
}
}
catch (Exception ex)
{
throw;
}
}
开发者ID:jklemmack,项目名称:IoTIrrigationController,代码行数:29,代码来源:MainPage.xaml.cs
示例8: Timer_Tick
private async void Timer_Tick(ThreadPoolTimer timer)
{
try
{
//perform inventory scan and read available RFID tags
var tagInventory = await _reader.PerformInventoryScan();
if(tagInventory.Count() > 0)
{
//assemble readings in the expected structure
List<TrackerReadingModel> readings = new List<TrackerReadingModel>();
foreach(var tag in tagInventory)
{
TrackerReadingModel reading = new TrackerReadingModel();
reading.IpAddress = _ipAddress;
reading.TagId = BitConverter.ToString(tag);
reading.Reading = DateTime.Now;
readings.Add(reading);
}
//send reading data to the cloud service
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://YOURBASEURL.COM/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PostAsJsonAsync("api/reading/add-multi-readings", readings);
}
}
}
catch (Exception ex)
{
//TODO: Logging of exception
}
}
开发者ID:codingbandit,项目名称:RfidScanner,代码行数:34,代码来源:StartupTask.cs
示例9: LogTemperatures
void LogTemperatures(ThreadPoolTimer timer)
{
try
{
using (var oneWireDeviceHandler = new OneWireDeviceHandler())
{
foreach (var device in oneWireDeviceHandler.GetDevices<DS18S20>())
{
var result = device.GetTemperature();
var extendedResult = device.GetExtendedTemperature();
// Insert code to log result in some way
}
foreach (var device in oneWireDeviceHandler.OneWireDevices.GetDevices<DS18B20>())
{
var result = device.GetTemperature();
// Insert code to log result in some way
}
}
}
catch (Exception e)
{
// Insert code to log all exceptions!
}
}
开发者ID:vgilbertsson,项目名称:OneWire,代码行数:27,代码来源:StartupTask.cs
示例10: Controller
public Controller(Func<string, int> callback)
{
_callback = callback;
_timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(5000));
_gpio_controller = GpioController.GetDefault();
// Create the Area(s)
_areas = new List<Area>() { new Area( "Area 1",
new List<Zone>() { new Zone("Zone 1", _gpio_controller.OpenPin(ZONE_1)) },
new Flow("Flow 1", _gpio_controller.OpenPin(FLOW_1)),
new OverCurrent("OC 1", _gpio_controller.OpenPin(OC_1)),
callback )};
/*
_areas = new List<Area>() { new Area( "Area 1",
new List<Zone>() { new Zone("Zone 1", _gpio_controller.OpenPin(ZONE_1)),
new Zone("Zone 2", _gpio_controller.OpenPin(ZONE_2)),
new Zone("Zone 3", _gpio_controller.OpenPin(ZONE_3))
},
new Flow("Flow 1", _gpio_controller.OpenPin(FLOW_1)),
new OverCurrent("OC 1", _gpio_controller.OpenPin(OC_1)),
callback ),
new Area( "Area 2",
new List<Zone>() { new Zone("Zone 4", _gpio_controller.OpenPin(ZONE_4)),
new Zone("Zone 5", _gpio_controller.OpenPin(ZONE_5))
},
new Flow("Flow 2", _gpio_controller.OpenPin(FLOW_1)),
new OverCurrent("OC 2", _gpio_controller.OpenPin(OC_1)),
callback )
};
*/
}
开发者ID:micklab,项目名称:isavewater,代码行数:34,代码来源:controller.cs
示例11: Timer_Tick
private async void Timer_Tick(ThreadPoolTimer timer)
{
_timer.Cancel();
SwitchLed(true);
try
{
//var tempHumid = DeviceFactory.Build.TemperatureAndHumiditySensor(Pin.DigitalPin4, GrovePi.Sensors.TemperatureAndHumiditySensorModel.DHT11).TemperatureAndHumidity();
//Debug.WriteLine(string.Format("Temperature={0} Humidity={1}", tempHumid.Temperature, tempHumid.Humidity));
Int16 temp = 20; // Convert.ToInt16(tempHumid.Temperature);
byte hum = 45; // Convert.ToByte(tempHumid.Humidity);
using (var stream = new MemoryStream())
{
using (var writer = new BinaryWriter(stream))
{
writer.Write(temp);
writer.Write(hum);
writer.Flush();
}
await _sigfox.SendAsync(stream.ToArray());
}
}
finally
{
SwitchLed(false);
}
}
开发者ID:danvy,项目名称:iot-toolkit,代码行数:26,代码来源:StartupTask.cs
示例12: PeriodicTimerCallback
private void PeriodicTimerCallback(ThreadPoolTimer timer)
{
if (ValueChangeCompleted == null)
{
return;
}
if (_simulatorGoingUp)
{
_startSimulatorValue = (ushort)(_startSimulatorValue + _stepSimulatorValue);
if (_startSimulatorValue > _maxSimulatorValue)
{
_startSimulatorValue = _maxSimulatorValue;
_simulatorGoingUp = false;
}
}
else
{
_startSimulatorValue = (ushort)(_startSimulatorValue - _stepSimulatorValue);
if (_startSimulatorValue < _minSimulatorValue)
{
_startSimulatorValue = _minSimulatorValue;
_simulatorGoingUp = true;
}
}
ValueChangeCompleted(HeartbeatMeasurement.GetHeartbeatMeasurementFromData(_startSimulatorValue, DateTimeOffset.Now));
}
开发者ID:DrJukka,项目名称:Heart-rate-monitor-UWP-,代码行数:28,代码来源:HeartBeatEngine.cs
示例13: BlinkyExample
public BlinkyExample(RemoteDevice arduino, int millisecodInterval)
{
Arduino = arduino;
Interval = millisecodInterval;
timer = ThreadPoolTimer.CreatePeriodicTimer(OnTimerElapsed,
TimeSpan.FromMilliseconds(millisecodInterval));
}
开发者ID:WCMoses,项目名称:Win10-Universal-IoT-Arduino-Samples,代码行数:7,代码来源:BlinkyExample.cs
示例14: Run
public void Run(IBackgroundTaskInstance taskInstance)
{
deferral = taskInstance.GetDeferral();
//Motor starts off
currentPulseWidth = 0;
//The stopwatch will be used to precisely time calls to pulse the motor.
stopwatch = Stopwatch.StartNew();
GpioController controller = GpioController.GetDefault();
servoPin = controller.OpenPin(13);
servoPin.SetDriveMode(GpioPinDriveMode.Output);
timer = ThreadPoolTimer.CreatePeriodicTimer(this.Tick, TimeSpan.FromSeconds(2));
//You do not need to await this, as your goal is to have this run for the lifetime of the application
Windows.System.Threading.ThreadPool.RunAsync(this.MotorThread, Windows.System.Threading.WorkItemPriority.High);
}
开发者ID:ChrisKaps,项目名称:samples,代码行数:25,代码来源:StartupTask.cs
示例15: PopulateWeatherData
private void PopulateWeatherData(ThreadPoolTimer timer)
{
bool hasMutex = false;
try
{
hasMutex = mutex.WaitOne(1000);
if (hasMutex)
{
weatherData.TimeStamp = DateTime.Now.ToLocalTime().ToString();
shield.BlueLEDPin.Write(Windows.Devices.Gpio.GpioPinValue.High);
weatherData.Altitude = shield.Altitude;
weatherData.BarometricPressure = shield.Pressure;
weatherData.CelsiusTemperature = shield.Temperature;
weatherData.FahrenheitTemperature = (weatherData.CelsiusTemperature * 9 / 5) + 32;
weatherData.Humidity = shield.Humidity;
shield.BlueLEDPin.Write(Windows.Devices.Gpio.GpioPinValue.Low);
// Push the WeatherData local/cloud storage (viewable at http://iotbuildlab.azurewebsites.net/)
WriteDataToIsolatedStorage();
SendDataToConnectTheDots();
}
}
finally
{
if (hasMutex)
{
mutex.ReleaseMutex();
}
}
}
开发者ID:ruisebastiao,项目名称:iot-build-lab,代码行数:34,代码来源:StartupTask.cs
示例16: Run
public async void Run(IBackgroundTaskInstance taskInstance)
{
// Ensure our background task remains running
taskDeferral = taskInstance.GetDeferral();
// Mutex will be used to ensure only one thread at a time is talking to the shield / isolated storage
mutex = new Mutex(false, mutexId);
// Initialize ConnectTheDots Settings
localSettings.ServicebusNamespace = "YOURSERVICEBUS-ns";
localSettings.EventHubName = "ehdevices";
localSettings.KeyName = "D1";
localSettings.Key = "YOUR_KEY";
localSettings.DisplayName = "YOUR_DEVICE_NAME";
localSettings.Organization = "YOUR_ORGANIZATION_OR_SELF";
localSettings.Location = "YOUR_LOCATION";
SaveSettings();
// Initialize WeatherShield
await shield.BeginAsync();
// Create a timer-initiated ThreadPool task to read data from I2C
i2cTimer = ThreadPoolTimer.CreatePeriodicTimer(PopulateWeatherData, TimeSpan.FromSeconds(i2cReadIntervalSeconds));
// Start the server
server = new HttpServer(port);
var asyncAction = ThreadPool.RunAsync((w) => { server.StartServer(weatherData); });
// Task cancellation handler, release our deferral there
taskInstance.Canceled += OnCanceled;
// Create a timer-initiated ThreadPool task to renew SAS token regularly
SASTokenRenewTimer = ThreadPoolTimer.CreatePeriodicTimer(RenewSASToken, TimeSpan.FromMinutes(15));
}
开发者ID:ruisebastiao,项目名称:iot-build-lab,代码行数:35,代码来源:StartupTask.cs
示例17: PeriodicTimerCallback
//
// Simulate the background task activity.
//
private void PeriodicTimerCallback(ThreadPoolTimer timer)
{
if ((_cancelRequested == false) && (_progress < 100))
{
_progress += 10;
_taskInstance.Progress = _progress;
}
else
{
_periodicTimer.Cancel();
var settings = ApplicationData.Current.LocalSettings;
var key = _taskInstance.Task.Name;
//
// Write to LocalSettings to indicate that this background task ran.
//
settings.Values[key] = (_progress < 100) ? "Canceled with reason: " + _cancelReason.ToString() : "Completed";
Debug.WriteLine("Background " + _taskInstance.Task.Name + settings.Values[key]);
//
// Indicate that the background task has completed.
//
_deferral.Complete();
}
}
开发者ID:jakkaj,项目名称:DayBar,代码行数:29,代码来源:Class1.cs
示例18: Start
public override async void Start()
{
if (_Started)
return;
_SequenceNumber = 1;
try
{
// Connect to the Drone
udpClient = new DatagramSocket();
await udpClient.BindServiceNameAsync(_ServiceName);
await udpClient.ConnectAsync(new HostName(DroneClient.Host), _ServiceName);
udpWriter = new DataWriter(udpClient.OutputStream);
udpWriter.WriteByte(1);
await udpWriter.StoreAsync();
_Timer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(timerElapsedHandler), TimeSpan.FromMilliseconds(25));
_Started = true;
}
catch (Exception)
{
Stop();
}
}
开发者ID:Eggies,项目名称:SDK,代码行数:25,代码来源:CommandWorker.cs
示例19: Run
public async void Run(IBackgroundTaskInstance taskInstance) {
await LogToFile("Run()");
try {
// Ensure our background task remains running
taskDeferral = taskInstance.GetDeferral();
// Initiate the SPI
InitSPI();
// test nå..
//ReadTemperature(null);
// Create a timer-initiated ThreadPool task to read data from I2C
i2cTimer = ThreadPoolTimer.CreatePeriodicTimer(ReadTemperature, TimeSpan.FromSeconds(i2cReadIntervalSeconds));
// // Start the server
server = new HttpServer(port);
var asyncAction = ThreadPool.RunAsync(w => { server.StartServerAsync(temperatureData); });
// Task cancellation handler, release our deferral there
taskInstance.Canceled += OnCanceled;
} catch(Exception ex) {
await LogExceptionAsync(nameof(Run), ex);
if(Debugger.IsAttached) {
Debugger.Break();
}
// If it goes to shit here, rethrow which will terminate the process - but at least we have it logged!
throw;
}
await LogToFile("Run() done");
}
开发者ID:torgeirhansen,项目名称:SimpleWeatherStation,代码行数:33,代码来源:StartupTask.cs
示例20: Run
//
// The Run method is the entry point of a background task.
//
public void Run(IBackgroundTaskInstance taskInstance)
{
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Debug.WriteLine("Background " + taskInstance.Task.Name + " Starting...");
// For performing asynchronous operations in the background task
BackgroundTaskDeferral asyncDeferral = taskInstance.GetDeferral();
//
// Query BackgroundWorkCost
// Guidance: If BackgroundWorkCost is high, then perform only the minimum amount
// of work in the background task and return immediately.
//
var cost = BackgroundWorkCost.CurrentBackgroundWorkCost;
var settings = ApplicationData.Current.LocalSettings;
settings.Values["BackgroundWorkCost"] = cost.ToString();
//
// Associate a cancellation handler with the background task.
//
taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
//
// Get the deferral object from the task instance, and take a reference to the taskInstance;
//
_deferral = taskInstance.GetDeferral();
_taskInstance = taskInstance;
_periodicTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(PeriodicTimerCallback), TimeSpan.FromSeconds(1));
asyncDeferral.Complete();
}
开发者ID:vinayganesh,项目名称:Wp8.1BackgroundTask,代码行数:37,代码来源:TimerTrigger.cs
注:本文中的Windows.System.Threading.ThreadPoolTimer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论