teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

ソースコードの添付

2020/05/25 22:58

投稿

montai21
montai21

スコア17

title CHANGED
File without changes
body CHANGED
@@ -2,33 +2,129 @@
2
2
  プログラム動かす環境が一定時間ユーザの無操作状態が続くと、強制ログオフするようになっております。ユーザが業務終了後に、大容量のファイル(6GBくらい)をダウンロードするために、ダウンロードを予約し、また、予約を画面からキャンセルできるようにしたいと考えております。一定時間放置後にも予約をキャンセルできるようにしたいため、強制ログオフしないように、プログラムからマウス操作イベントを定期的に出力するようにしております。また、ダウンロード処理も同プログラム内で実行するようします。検証でおこなったところ、ダウンロード処理を走らせない場合は、一定時間放置しても、ディスプレイ電源offや強制ログオフは起こらなかったんですが、ダウンロード処理を走らせますと、プログラムが応答なしとなり、一定時間放置しますと、ディスプレイ電源がoffになりました。しかし、ダウンロード処理は時間がかかりますが、正常に終了します。ファイル容量が小さい場合は強制ログオフをかいひしつ
3
3
 
4
4
  #アドバイスいただきたいこと
5
- 事象に挙げた内容を踏まえ、強制ログオフが起きないようにしつつ、ダウンロード処理を行うにはどのようにすればよいでしょうか?
5
+ 0. 事象に挙げた内容を踏まえ、強制ログオフが起きないようにしつつ、ダウンロード処理を行うにはどのようにすればよいでしょうか?
6
- ダウンロード処理にファイル共有し、コピーを行っているのですが、ftpダウンロードの方が負荷が少ないでしょうか?
6
+ 0. ダウンロード処理にファイル共有し、コピーを行っているのですが、ftpダウンロードの方が負荷が少ないでしょうか?
7
+ 0. タイマースレッドを用いて、マウスイベントを定期的に出力しているのですが、以下のコードの書き方があまりよくないのでしょうか。
7
8
 
8
- #コンソールログ
9
+ #Form
9
10
  ```
11
+ using System;
12
+ using System.Diagnostics;
13
+ using System.IO;
14
+ using System.Windows.Forms;
15
+
16
+ namespace AidleStatusDisableApp
17
+ {
18
+ public partial class Form1 : Form
19
+ {
20
+ public Form1()
21
+ {
22
+ InitializeComponent();
23
+ }
24
+
25
+ private void button1_Click(object sender, EventArgs e)
26
+ {
10
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'item' not found. Available parameters are [collection, list]
27
+ const string commandMount = @"/c net use \servername\kyouyu password /user:user /PERSISTENT:NO";
28
+ ExecuteCommand(commandMount);
29
+ CopyFiles(@".\test.txt", @"\servername\kyouyu\testbigfile");
30
+ }
31
+
32
+ private void button2_Click(object sender, EventArgs e)
33
+ {
34
+
35
+ }
36
+
37
+ public void ExecuteCommand(string command)
38
+ {
39
+ using (var p = new Process())
40
+ {
41
+ //ComSpec(cmd.exe)のパスを取得して、FileNameプロパティに指定
42
+ p.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
43
+ ////ウィンドウを表示しないようにする
44
+ p.StartInfo.CreateNoWindow = true;
45
+ //コマンドラインを指定("/c"は実行後閉じるために必要)
46
+ p.StartInfo.Arguments = command;
47
+ //起動
48
+ p.Start();
49
+ p.WaitForExit();
50
+ }
51
+ }
52
+
53
+ public void CopyFiles(string srcfile, string dstfile)
54
+ {
55
+ File.AppendAllText(@".\log.txt", "コピーを開始します。" + DateTime.Now + Environment.NewLine);
56
+ System.IO.File.Copy(srcfile, dstfile, true);
57
+ File.AppendAllText(@".\log.txt", "コピーを終了します。" + DateTime.Now + Environment.NewLine);
58
+ }
59
+ }
60
+ }
61
+
11
62
  ```
12
63
 
13
- #xml
64
+ #Program
14
65
  ```
15
- <delete id="deleteById" parameterType="list">
16
- <![CDATA[
17
- DELETE FROM
18
- tbl_schedule
19
- WHERE task_id IN
20
- <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
21
- #{item}
66
+ using System;
67
+ using System.Runtime.InteropServices;
22
- </foreach>
68
+ using System.Threading;
23
- ]]>
24
- </delete>
69
+ using System.Windows.Forms;
25
- ```
70
+ using System.Threading.Timer
26
71
 
72
+ namespace AidleStatusDisableApp
73
+ {
74
+ public static class Program
75
+ {
76
+ const int MOUSEEVENTF_MOVED = 0x0001;
27
- #Java
77
+ [STAThread]
78
+ public static void Main()
79
+ {
80
+ TimerCallback callback = state =>
81
+ {
82
+ INPUT[] input = new INPUT[1]; // イベントを格納
83
+ // ドラッグ操作の準備 (イベントの定義 = 相対座標へ移動)
84
+ input[0].mi.dx = 0; // 相対座標で0 つまり動かさない
85
+ input[0].mi.dy = 0; // 相対座標で0 つまり動かさない
86
+ input[0].mi.dwFlags = MOUSEEVENTF_MOVED;
87
+ // ドラッグ操作の実行 (イベントの生成)
88
+ SendInput(1, input, Marshal.SizeOf(input[0]));
89
+ };
90
+
91
+ // タイマー起動(0.5秒後に処理実行、1秒おきに繰り返し)
92
+ Timer MyTimer = new System.Threading.Timer(callback, null, 500, 1000);
93
+ Application.EnableVisualStyles();
94
+ Application.SetCompatibleTextRenderingDefault(false);
95
+ Application.Run(new Form1());
96
+
97
+ }
98
+
99
+ [DllImport("user32.dll")]
100
+ extern static uint SendInput(
101
+ uint nInputs, // INPUT 構造体の数(イベント数)
102
+ INPUT[] pInputs, // INPUT 構造体
103
+ int cbSize // INPUT 構造体のサイズ
104
+ );
105
+
106
+ [StructLayout(LayoutKind.Sequential)]
107
+ struct INPUT
108
+ {
109
+ public int type; // 0 = INPUT_MOUSE(デフォルト), 1 = INPUT_KEYBOARD
110
+ public MOUSEINPUT mi;
111
+ }
112
+ [StructLayout(LayoutKind.Sequential)]
113
+ struct MOUSEINPUT
114
+ {
115
+ public int dx;
116
+ public int dy;
117
+ public int mouseData; // amount of wheel movement
118
+ public int dwFlags;
119
+ public int time; // time stamp for the event
120
+ public IntPtr dwExtraInfo;
121
+ }
122
+ }
123
+ }
124
+
28
125
  ```
29
- void deleteById(List<String> taskIdList);
30
- ```
31
126
 
127
+
128
+ ##環境
129
+ .Net Framework 4.6
32
- ##参考にしたサイト
130
+ Windows 10
33
- ・[https://mybatis.org/mybatis-3/ja/dynamic-sql.html](https://mybatis.org/mybatis-3/ja/dynamic-sql.html)
34
- ・[https://qiita.com/5zm/items/0864d6641c65f976d415](https://qiita.com/5zm/items/0864d6641c65f976d415)