사실 나는 stackoverflow에서 뭔가 simmilar를 발견하고, 그것은 나를 위해 작동하지 않았다. 그들은 주어진 시간 (23:00)에 그들의 응용 프로그램을 종료하고 싶었습니다. 나는 3000 초 후에 그것을 나가고 싶다. 나에게 대답은 도움이되었다. 이제는 중요한 부분인데,이 코드를 프로그램에 넣는 것이 중요하다.C#에서 x 초 후에 응용 프로그램을 종료하거나 닫는 방법?
이 코드는 멀티 빔 RFID 리더를 관리하여 태그를 현지화합니다. x와 y 좌표 (그리고 EPC, Timestamp, 보고서 유형 등의 다른 정보)를 제공합니다. 실제로 프로그램은 제대로 작동하지만 5 분 동안 만 실행하고 싶습니다. 리더기의 정확도를 측정하고 있는데 다른 설정을 사용하면 모든 측정 값이 3000 초 (또는 그 이상)이면 더 유사 할 것입니다. 이제 입력을 누르면 프로그램이 종료됩니다.
나는 많은 것을 찾고 노력했지만, 나를 위해 일하고 싶지 않습니다. 누군가가 여기서 도울 수 있기를 바랍니다.
using System;
using Impinj.OctaneSdk;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace OctaneSdkExamples
{
class Program
{
// Create an instance of the ImpinjReader class.
static ImpinjReader reader = new ImpinjReader();
static void Main(string[] args)
{
try
{
// Connect to the reader.
// Change the ReaderHostname constant in SolutionConstants.cs
// to the IP address or hostname of your reader.
reader.Connect(SolutionConstants.ReaderHostname);
// Assign the LocationReported event handler.
// This specifies which method to call
// when a location report is available.
reader.LocationReported += OnLocationReported;
// Get the default settings
// We'll use these as a starting point
// and then modify the settings we're
// interested in.
Settings settings = reader.QueryDefaultSettings();
// Put the xArray into location mode
settings.SpatialConfig.Mode = SpatialMode.Location;
// Enable all three report types
settings.SpatialConfig.Location.EntryReportEnabled = true;
settings.SpatialConfig.Location.UpdateReportEnabled = true;
settings.SpatialConfig.Location.ExitReportEnabled = true;
// Set xArray placement parameters
// The mounting height of the xArray, in centimeters
settings.SpatialConfig.Placement.HeightCm = 100
;
// These settings aren't required in a single xArray environment
// They can be set to zero (which is the default)
settings.SpatialConfig.Placement.FacilityXLocationCm = 0;
settings.SpatialConfig.Placement.FacilityYLocationCm = 0;
settings.SpatialConfig.Placement.OrientationDegrees = 0;
// Set xArray location parameters
settings.SpatialConfig.Location.ComputeWindowSeconds = 10;
settings.ReaderMode = ReaderMode.AutoSetDenseReader;
settings.Session = 2;
settings.SpatialConfig.Location.TagAgeIntervalSeconds = 20;
// Specify how often we want to receive location reports
settings.SpatialConfig.Location.UpdateIntervalSeconds = 5;
// Set this to true if the maximum transmit power is desired, false if a custom value is desired
settings.SpatialConfig.Location.MaxTxPower = false;
// If MaxTxPower is set to false, then a custom power can be used. Provide a power in .25 dBm increments
settings.SpatialConfig.Location.TxPowerInDbm = 23.00;
// Disable antennas targeting areas from which we may not want location reports,
// in this case we're disabling antennas 10 and 15
List<ushort> disabledAntennas = new List<ushort> { };
settings.SpatialConfig.Location.DisabledAntennaList = disabledAntennas;
// Uncomment this is you want to filter tags
/*
// Setup a tag filter.
// Only the tags that match this filter will respond.
// We want to apply the filter to the EPC memory bank.
settings.Filters.TagFilter1.MemoryBank = MemoryBank.Epc;
// Start matching at the third word (bit 32), since the
// first two words of the EPC memory bank are the
// CRC and control bits. BitPointers.Epc is a helper
// enumeration you can use, so you don't have to remember this.
settings.Filters.TagFilter1.BitPointer = BitPointers.Epc;
// Only match tags with EPCs that start with "3008"
settings.Filters.TagFilter1.TagMask = "3008";
// This filter is 16 bits long (one word).
settings.Filters.TagFilter1.BitCount = 16;
// Set the filter mode. Use only the first filter
settings.Filters.Mode = TagFilterMode.OnlyFilter1;
*/
// Apply the newly modified settings.
reader.ApplySettings(settings);
// Start the reader
reader.Start();
timer1_Tick(3000);
// Wait for the user to press enter.
Console.WriteLine("Press enter to exit");
Console.ReadLine();
// Apply the default settings before exiting.
reader.ApplyDefaultSettings();
// Disconnect from the reader.
reader.Disconnect();
}
catch (OctaneSdkException e)
{
// Handle Octane SDK errors.
Console.WriteLine("Octane SDK exception: {0}", e.Message);
}
catch (Exception e)
{
// Handle other .NET errors.
Console.WriteLine("Exception : {0}", e.Message);
}
}
// This event handler will be called when a location report is ready.
static void OnLocationReported(ImpinjReader reader, LocationReport report)
{
// Print out the report details
Console.WriteLine("Location report");
Console.WriteLine(" Type = {0}", report.ReportType);
Console.WriteLine(" EPC = {0}", report.Epc);
Console.WriteLine(" X = {0} cm", report.LocationXCm);
Console.WriteLine(" Y = {0} cm", report.LocationYCm);
Console.WriteLine(" Timestamp = {0} ({1})", report.Timestamp, report.Timestamp.LocalDateTime);
Console.WriteLine(" Read count = {0}", report.ConfidenceFactors.ReadCount);
// Saving data
string path = @"b:\Master Thesis\xArray\Tests\Test 3 - Height-100cm, Disabled Antennas - , TxPowerInDbm-23.25, UpdateIntervalSeconds-5, ComputeWindowSeconds-10, ReaderMode_AutoSetDenseReader, TagAgeIntervalSeconds-20, tags 40 cm from origo .txt";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Type, Epc, X Localization, Y localization, Timestamp, Local Date Time, Read Count ");
// This text is added only once to the file.
}
}
// This text is always added, making the file longer over time
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(" {0} , {1} , {2} , {3} , {4} , {5} , {6} ", report.ReportType, report.Epc, report.LocationXCm, report.LocationYCm, report.Timestamp, report.Timestamp.LocalDateTime, report.ConfidenceFactors.ReadCount);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
reader.Disconnect();
}
}
}
글쎄'Console.ReadLine(); '는 입력이 예상대로 열려있는 프로그램을 유지하는 것입니다 무엇을, 네가 그것을 원한다면 왜 그곳에 있는가? – Equalsk
최소한의 완전한 입증 가능한 예제를 게시하는 것이 좋습니다. http://stackoverflow.com/help/mcve – chadnt
가능한 [타이머를 닫아 응용 프로그램] (http://stackoverflow.com/questions/13626454/timer-to-close-the-application) –