시작버튼에서 마우스 우클릭 메뉴에서 윈도우 파워쉘(관리자모드) 로 실행

 

 

 

DISM.exe /Online /Cleanup-Image /Restorehealth 명령어 실행

 

 

아래처럼 빌드시에는 이상이 없었는데

기기로 디버깅 시 에러가 발생되었다.

 

System.TypeLoadException: Could not load type of field 'Xamarin.Forms.Platform.Android.RendererPool:_freeRenderers' (0) due to: Could not resolve type with token 010001b1 from typeref (expected class 'System.Collections.Generic.Stack`1' in assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e') assembly:mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e type:System.Collections.Generic.Stack`1 member:(null)

 

찾아보니 Forms 버전을 다운 그레이드 하면 해결되는데 (4.1.0.778454 버전으로 다운 그레이드)

 

 

Android 쪽 패키들과 버전 충돌때문에 다운그레이드가 잘되지 않았다. ㅠㅜ

 

 

그래서 위 목록을 모두 제거하고 Forms 버전은 4.1.0.778454 으로 설치

나머지 Android 쪽 패키지들은 28.0.0.1 (낮은)버전으로 설치하고 실행하니 정상적으로 동작되었다.

 

아래는 재설치후 버전들..

 

 

 

 

 

DevExpress 의 PanelControl 에서 스크롤 속성이 없다.

그래서 XtraScrollableControl 컨트롤을 사용하는데

여기에 다른 컨트롤을 갖다 놓으면 스크롤을 휠로 제어할수 없게된다ㅜㅠ

 

이를 위해선 아래 처럼 ScrollHelper 를 선언한후

XtraScrollableControl 컨트롤이 들어간 화면 초입에 아래처럼 코딩하면

문제없이 휠로도 스크롤이 가능해진다.

 

ScrollHelper scrollHelper = new ScrollHelper();

scrollHelper.EnableScrollOnMouseWheel();

 

또한 화면이 Dispose() 이벤트에서 아래처럼

기능을 꺼야한다.

scrollHelper.DisableScrollOnMouseWheel();

 

 

    public class ScrollHelper

    {

        XtraScrollableControl scrollableControl;

 

        public ScrollHelper(XtraScrollableControl scrollableControl)

        {

            this.scrollableControl = scrollableControl;

        }

 

        public void EnableScrollOnMouseWheel()

        {

            scrollableControl.VisibleChanged += OnVisibleChanged;

        }

 

        void OnVisibleChanged(object sender, EventArgs e)

        {

            scrollableControl.Select();

            UnsubscribeFromMouseWheel(scrollableControl.Controls);

            SubscribeToMouseWheel(scrollableControl.Controls);

        }

 

        private void SubscribeToMouseWheel(Control.ControlCollection controls)

        {

            foreach (Control ctrl in controls)

            {

                ctrl.MouseWheel += OnMouseWheel;

                SubscribeToMouseWheel(ctrl.Controls);

            }

        }

 

        private void UnsubscribeFromMouseWheel(Control.ControlCollection controls)

        {

            foreach (Control ctrl in controls)

            {

                ctrl.MouseWheel -= OnMouseWheel;

                UnsubscribeFromMouseWheel(ctrl.Controls);

            }

        }

 

        void OnMouseWheel(object sender, MouseEventArgs e)

        {

            DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;

            int scrollValue = scrollableControl.VerticalScroll.Value;

            int largeChange = scrollableControl.VerticalScroll.LargeChange;

            if (e.Delta < 0)

                scrollableControl.VerticalScroll.Value += scrollableControl.VerticalScroll.LargeChange;

            else

                if (scrollValue < largeChange)

                scrollableControl.VerticalScroll.Value = 0;

            else

                scrollableControl.VerticalScroll.Value -= largeChange;

        }

 

        public void DisableScrollOnMouseWheel()

        {

            scrollableControl.VisibleChanged -= OnVisibleChanged;

            UnsubscribeFromMouseWheel(scrollableControl.Controls);

            scrollableControl = null;

        }

    }

 

 

참고

https://www.devexpress.com/Support/Center/Question/Details/K18512/how-to-enable-scrolling-in-xtrascrollablecontrol-by-using-the-mouse-wheel

webRequest 호출시 (401) Unauthorized 에러가 발생한 경우 처리한다.

 

HttpWebRequest myReq = ...

myReq.UseDefaultCredentials = true;

myReq.PreAuthenticate      = true;

myReq.Credentials          = CredentialCache.DefaultCredentials;

 

 

참고

https://stackoverflow.com/questions/10205854/error-the-remote-server-returned-an-error-401-unauthorized

어느날 C 드라이브가 용량이 좀 차서

파일을 정리하는데 엄청난양의 Nuget Package 파일들이 디스크 용량을

잡아 먹고 있는걸 확인했다.

이를 수동으로 지우기 보다는 Visual Studio 에서 지우는 방법이 있다.

Visual Studio 에서 도구>옵션 의 옵션창에서

Nuget 패키지 관리자를 선택하면 '모든 NuGet 캐시 지우기' 버튼이 있는데

이를 클릭하면 삭제 할수 있다.

 

https://robgibbens.com/deploying-a-database-file-with-a-xamarin-forms-app/

https://csharp.hotexamples.com/examples/ZXing.Net.Mobile.Forms/ZXingScannerPage/-/php-zxingscannerpage-class-examples.html




1.

https://stackoverflow.com/questions/989281/how-can-i-programmatically-limit-my-programs-cpu-usage-to-below-70

아래 내용은 Process.Start() 이후

process.PriorityClass = ProcessPriorityClass.BelowNormal;

처리를 해줘야 효과를 볼수 있다.

 

    public static class ProcessHelper

    {

        [Flags]

        public enum ThreadAccess : int

        {

            TERMINATE = (0x0001),

            SUSPEND_RESUME = (0x0002),

            GET_CONTEXT = (0x0008),

            SET_CONTEXT = (0x0010),

            SET_INFORMATION = (0x0020),

            QUERY_INFORMATION = (0x0040),

            SET_THREAD_TOKEN = (0x0080),

            IMPERSONATE = (0x0100),

            DIRECT_IMPERSONATION = (0x0200)

        }

 

        [DllImport("kernel32.dll")]

        static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);

 

        [DllImport("kernel32.dll")]

        static extern uint SuspendThread(IntPtr hThread);

 

        [DllImport("kernel32.dll")]

        static extern int ResumeThread(IntPtr hThread);

 

        [DllImport("kernel32.dll")]

        static extern int CloseHandle(IntPtr hThread);

 

        public static void ThrottleProcess(int processId, double limit)

        {

            var process = Process.GetProcessById(processId);

            var processName = process.ProcessName;

            var p = new PerformanceCounter("Process", "% Processor Time", processName);

            while (true)

            {

                var interval = 100;

                Thread.Sleep(interval);

 

                var currentUsage = p.NextValue() / Environment.ProcessorCount;

                if (currentUsage < limit) continue;

                var suspensionTime = (currentUsage-limit) / currentUsage * interval;

                SuspendProcess(processId);

                Thread.Sleep((int)suspensionTime);

                ResumeProcess(processId);

            }

        }

 

        private static void SuspendProcess(int pid)

        {

            var process = Process.GetProcessById(pid);

 

            if (process.ProcessName == string.Empty)

                return;

 

            foreach (ProcessThread pT in process.Threads)

            {

                IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);

 

                if (pOpenThread == IntPtr.Zero)

                {

                    continue;

                }

 

                SuspendThread(pOpenThread);

 

                CloseHandle(pOpenThread);

            }

        }

 

        private static void ResumeProcess(int pid)

        {

            var process = Process.GetProcessById(pid);

 

            if (process.ProcessName == string.Empty)

                return;

 

            foreach (ProcessThread pT in process.Threads)

            {

                IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);

 

                if (pOpenThread == IntPtr.Zero)

                {

                    continue;

                }

 

                var suspendCount = 0;

 

                do

                {

                    suspendCount = ResumeThread(pOpenThread);

                } while (suspendCount > 0);

 

                CloseHandle(pOpenThread);

            }

        }

    }

 

2.

https://stackoverflow.com/questions/989281/how-can-i-programmatically-limit-my-programs-cpu-usage-to-below-70

 

아래 내용은 process.PriorityClass = ProcessPriorityClass.BelowNormal 처리를 하지 않아도 효과를 볼수 있다.

이 내용이 확실하게 제어를 해주는것 같다

 

    public class ProcessManager

    {

        [DllImport("kernel32.dll", EntryPoint = "CreateJobObjectW", CharSet = CharSet.Unicode)]

        public static extern IntPtr CreateJobObject(SecurityAttributes JobAttributes, string lpName);

 

        [DllImport("kernel32.dll")]

        [return: MarshalAs(UnmanagedType.Bool)]

        static extern bool AssignProcessToJobObject(IntPtr hJob, IntPtr hProcess);

 

        [DllImport("kernel32.dll")]

        static extern bool SetInformationJobObject(IntPtr hJob, JOBOBJECTINFOCLASS JobObjectInfoClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);

 

        public class SecurityAttributes

        {

            public int nLength;

            public IntPtr pSecurityDescriptor;

            public bool bInheritHandle;

 

            public SecurityAttributes()

            {

                this.bInheritHandle = true;

                this.nLength = 0;

                this.pSecurityDescriptor = IntPtr.Zero;

            }

        }

 

        public enum JOBOBJECTINFOCLASS

        {

            JobObjectAssociateCompletionPortInformation = 7,

            JobObjectBasicLimitInformation = 2,

            JobObjectBasicUIRestrictions = 4,

            JobObjectEndOfJobTimeInformation = 6,

            JobObjectExtendedLimitInformation = 9,

            JobObjectSecurityLimitInformation = 5,

            JobObjectCpuRateControlInformation = 15

        }

 

        [StructLayout(LayoutKind.Explicit)]

        //[CLSCompliant(false)]

        struct JOBOBJECT_CPU_RATE_CONTROL_INFORMATION

        {

            [FieldOffset(0)]

            public UInt32 ControlFlags;

            [FieldOffset(4)]

            public UInt32 CpuRate;

            [FieldOffset(4)]

            public UInt32 Weight;

        }

 

        public enum CpuFlags

        {

            JOB_OBJECT_CPU_RATE_CONTROL_ENABLE = 0x00000001,

            JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED = 0x00000002,

            JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP = 0x00000004

        }

 

        public static void ThrottleProcess(Process process)

        {

            //Limit the CPU usage to 45%

            var jobHandle = CreateJobObject(null, null);

            AssignProcessToJobObject(jobHandle, process.Handle);

            var cpuLimits = new JOBOBJECT_CPU_RATE_CONTROL_INFORMATION();

            cpuLimits.ControlFlags = (UInt32)(CpuFlags.JOB_OBJECT_CPU_RATE_CONTROL_ENABLE | CpuFlags.JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP);

            cpuLimits.CpuRate = 45 * 100; // Limit CPu usage to 45%

            var pointerToJobCpuLimits = Marshal.AllocHGlobal(Marshal.SizeOf(cpuLimits));

            Marshal.StructureToPtr(cpuLimits, pointerToJobCpuLimits, false);

            if (!SetInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectCpuRateControlInformation, pointerToJobCpuLimits, (uint)Marshal.SizeOf(cpuLimits)))

            {

                Console.WriteLine("Error !");

            }

        }

    }

 

 

사용예시

 

Process process = new Process();

process.EnableRaisingEvents   = false;

process.StartInfo.FileName    = "Test.exe";

//process.StartInfo.Verb        = "Open";

process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

//process.StartInfo.Arguments   = argument;

 

process.Start();

 

// 1번 방법

process.PriorityClass = ProcessPriorityClass.BelowNormal;

ProcessHelper.ThrottleProcess(process.Id, 0.5);

 

// 2번 방법

ProcessManager.ThrottleProcess(process);

 



+ Recent posts