第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

windos服務(wù)實(shí)現(xiàn)定時(shí)寫(xiě)文件

windos服務(wù)實(shí)現(xiàn)定時(shí)寫(xiě)文件

鴻蒙傳說(shuō) 2018-12-06 23:52:33
我寫(xiě)了個(gè)windos往文件夾里寫(xiě)東西,但是不行啊,代碼如下: Installer1.Designer.cs中的 ??????? private System.ComponentModel.IContainer components = null;??????? private System.ServiceProcess.ServiceProcessInstaller spInstaller;??????? private System.ServiceProcess.ServiceInstaller sInstaller;??????? /// <summary> ??????? /// /// 清理所有正在使用的資源。 ??????? /// /// </summary>???? ??????? /// /// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>? ??????? protected override void Dispose(bool disposing)??????? {??????????? if (disposing && (components != null))??????????? {??????????????? components.Dispose();??????????? }??????????? base.Dispose(disposing);??????? } ??????? /// <summary>???????? #region 組件設(shè)計(jì)器生成的代碼??????? /// /// 設(shè)計(jì)器支持所需的方法 - 不要?? ??????? /// /// 使用代碼編輯器修改此方法的內(nèi)容。? ??????? /// /// </summary>????? ??????? private void InitializeComponent()??????? {??????????? components = new System.ComponentModel.Container();??????????? // 創(chuàng)建ServiceProcessInstaller對(duì)象和ServiceInstaller對(duì)象??????? ??????????? this.spInstaller = new System.ServiceProcess.ServiceProcessInstaller();??????????? this.sInstaller = new System.ServiceProcess.ServiceInstaller();??????????? // 設(shè)定ServiceProcessInstaller對(duì)象的帳號(hào)、用戶(hù)名和密碼等信息?? ??????????? this.spInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;??????????? this.spInstaller.Password = null;??????????? this.spInstaller.Username = null;??????????? // 設(shè)定服務(wù)的名稱(chēng)?????????? ??????????? this.sInstaller.ServiceName = "WindowsService1";??????????? //設(shè)定服務(wù)啟動(dòng)的方式???????? ??????????? this.sInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;??????????? this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.spInstaller, this.sInstaller });??????? }在創(chuàng)建的安裝程序類(lèi)中是 ??????? Timer time;??????? public Service1()??????? {??????????? InitializeComponent();??????? } ??????? protected override void OnStart(string[] args)??????? {??????????? time = new Timer(1000);     ???? time.Start(); ??????????? time.Elapsed += new ElapsedEventHandler(time_Elapsed); ??????? } ??????? void time_Elapsed(object sender, ElapsedEventArgs e)??????? {??????????? string filePath = AppDomain.CurrentDomain.BaseDirectory + "test.txt"; ??????????? StreamWriter sw = null;??????????? if (!File.Exists(filePath)) { ??????????????? sw = File.CreateText(filePath); ??????????? } else {??????????????? sw = File.AppendText(filePath);??????????? } ??????????? sw.Write("訪問(wèn)時(shí)間:" + DateTime.Now.ToString() + Environment.NewLine); sw.Close();??????? } ??????? protected override void OnStop()??????? {??????????? time.Stop(); ??????????? time.Dispose();??????? }但是我吧這個(gè)服務(wù)添加到window服務(wù)中,服務(wù)也啟動(dòng)了,但是文件沒(méi)有生產(chǎn)。怎么回事啊。
查看完整描述

4 回答

?
翻過(guò)高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊

你的timer 沒(méi)有打開(kāi)定時(shí)執(zhí)行

?timer1.Start();

查看完整回答
反對(duì) 回復(fù) 2019-01-21
?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

我加上了,但是不行還是,對(duì)嗎
查看完整回答
反對(duì) 回復(fù) 2019-01-21
?
慕標(biāo)琳琳

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊

@水淼:你的timer是那個(gè)timer? .net中有3個(gè)timer組件?!苍敿?xì)使googel一下〕 System.Windows.Forms.Timer System.Threading.Timer System.Timers.Timer 在服務(wù)中你應(yīng)該用System.Timers.Timer 。
查看完整回答
反對(duì) 回復(fù) 2019-01-21
  • 4 回答
  • 0 關(guān)注
  • 438 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)