본문 바로가기
728x90
반응형

.Net7

.NetCore 배포 폴더 만들기 C# .netcore3.1 배포 및 게시 방법 한번 알아봄 프로젝트 우클릭 후 게시 클릭 게시에서 폴더 클릭 후 다음 클릭 다음 게시에서도 폴더 클릭 후 다음 클릭 마침 클릭 게시 클릭 하면 프로젝트 빌드되기 시작함 빌드가 끝나면 해당 경로에 publish 폴더가 생성 되고 그 안에 프로젝트 생성됨 2023. 6. 12.
C# DateTime Ticks to Seconds TimeSpan 활용 사용한 시간 구하기 C#에서 현재시간을 저장하고 그다음 작업까지 걸리는 시간을 구하는 방법 long startTime = DateTime.Now.Ticks; Thread.Sleep(1000); 현재 시간을 startTime 변수가 저장 1초만큼 대기 후 long checkTime = DateTime.Now.Ticks - startTime; 현재시간에서 이전에 저장한 시간을 빼줌 TimeSpan elapsedSpan = new TimeSpan(checkTime); TimeSpan은 두 날짜 간의 차이를 알 수 있는 구조체 TimeSpan선언 후 계산된 시간 할당 Console.WriteLine(" {0:N0} nanoseconds", checkTime * 100); Console.WriteLine(" {0:N0} ticks".. 2022. 10. 12.
C# WPF 다른 스레드가 이 개체를 소유하고 있어 호출 스레드가 해당 개체에 액세스할 수 없습니다. C# 스레드 오류 Thread를 실행하다 보면 자주 발견할 수 있는 오류 보통 UI 화면에서 Data 가져올 때 문제가 발생된다. 아래와 같이 Dispatcher.Invoke문을 사용하면 해결된다.. using System.Windows.Threading; Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { string data = text.Text; })); 참조 https://learn.microsoft.com/ko-kr/dotnet/api/system.windows.threading.dispatcher.invoke?view=windowsdesktop-6.0 2022. 10. 5.
C# List Generic Struct/txt Save 리스트 배열 구조체 텍스트 저장 C#에서 Generic List를 텍스트 또는 구조체로 저장하는 방법 1. txt 저장 List val = new List(); private void test() { string time = DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss"); StreamWriter sw = new StreamWriter(time + ".txt"); for (int i = 0; i < val.Count; i++) { sw.Write(val[i]); } sw.Close(); } 위 방법으로 저장 시 for문이 돌기 때문에 배열 개수가 많을수록 시간이 많이 걸림 2. 구조체 저장 public struct DataList { public string data; } DataList dl = new.. 2022. 9. 29.
C# 텍스트 파일(txt) 쓰기 읽기 C#에서 사용가능 한 아주 간단한 txt 파일 읽기 쓰기 private void btn_Save_Click(object sender, RoutedEventArgs e) { string save_data = string.Format("{0},{1},{2},{3},{4},{5}", txt_X.Text, txt_Y.Text, txt_Z.Text, txt_A.Text, txt_B.Text, txt_C.Text); System.IO.File.WriteAllText("test.txt", save_data, Encoding.ASCII); string read = System.IO.File.ReadAllText("test.txt"); MessageBox.Show(read); } 버튼 클릭 시 데이터가 저장되고 저장된 .. 2022. 9. 27.
C# WPF Serial 통신 연결 가끔 사용하는 C# Serial 통신 사용할때 마다 잊어버려서 기록해놓으려고 한다. UI는 WPF로 작성 using System; using System.Collections; using System.IO.Ports; using System.Threading; using System.Windows; using System.Windows.Threading; namespace robot_arduino_test { public partial class MainWindow : Window { Queue Data = new Queue(); //데이터 저장 큐 SerialPort sp = new SerialPort(); string T_msg = ""; //WPF Text 저장용 public MainWindow().. 2022. 9. 27.
C#/WPF MainWindow Dual monitor setup 듀얼모니터 사용시 프로그램 화면 설정 MonitorCount 가 2 이상이면 설정가능 아래의 배열로 설정가능 AllScreens[0] AllScreens[1] if (System.Windows.Forms.SystemInformation.MonitorCount > 1) { System.Drawing.Rectangle secondaryScreenRectangle = System.Windows.Forms.Screen.AllScreens[0].WorkingArea; Window w = sender as Window; w.WindowState = WindowState.Normal; w.WindowStyle = WindowStyle.None; w.WindowStartupLocation = WindowStartupL.. 2022. 9. 16.
728x90
반응형