Condensing an if

I was hoping to get some help with this. The only real issue I'm having is that this code is not as efficient as it could be. Basically I have a set of tiles and need to decide what kind of tiles to instantiate based on the combination of tiles around them. In the code below, the position of the tile I'm checking is the key in my map (ex map[right] is the tile to the right, topLeft is

凝结如果

我希望能得到一些帮助。 我遇到的唯一真正的问题是这个代码并不像它可能的那样高效。 基本上我有一套瓷砖,需要根据它们周围的瓷砖组合来决定实例化哪种瓷砖。 在下面的代码中,我正在检查的瓦片的位置是我的地图中的关键字(例如,[右侧]是右侧的瓦片,topLeft是与左上角相邻的瓦片,top2等于瓦片在那个方向上有两个空间)。 有问题的代码: if (map[left].Type == TileType.WALL && map[top].Type == TileType.WA

Branch in C# Based on Boolean Pattern?

Need to branch in C# (.NET 4.6.1) based on one of 16 different boolean patterns in an array (for readability in this message, 0==false and 1==true): 0000 0010 0100 0110 0001 0011 0101 0111 1000 1010 1100 1110 1001 1011 1101 1111 Not being concerned with overall performance at this time, what is a good way to make the branching human-readable for e

C#中基于布尔模式的分支?

需要基于数组中16种不同布尔模式之一(为了在此消息中可读,0 == false和1 == true)而在C#(.NET 4.6.1)中进行分支: 0000 0010 0100 0110 0001 0011 0101 0111 1000 1010 1100 1110 1001 1011 1101 1111 不关心目前的整体表现,对于16个案例中的每一个案例来说,让分支可读的好方法是什么? 一些中间有“00”的人应该表现得一样,其他人则没有。 一个想法是将每个模式转

Changing text in label make text align not working?

Here's the things i have done with my label in runtime:(C#) label.Text = sometext; label.TextAlign = ContentAlignment.MiddleCenter; label.Invalidate(); label.Update(); label.Refresh(); label.PerformLayout(); And after the window is shown, before this code runs, the default text aligns perfectly in middle center. after this code runs, the text is aligned top left. The autosize is false f

更改标签中的文本使文本对齐不起作用?

以下是我在运行时用标签完成的工作:(C#) label.Text = sometext; label.TextAlign = ContentAlignment.MiddleCenter; label.Invalidate(); label.Update(); label.Refresh(); label.PerformLayout(); 在窗口显示之后,在此代码运行之前,默认文本在中间中心完美对齐。 这段代码运行后,文本左上角对齐。 标签的autosize为false。 现在,我在哪里做错了? 更新: 我发现了一个部分解决方案,但不知道为什么对我自

How would I run an async Task<T> method synchronously?

I'm learning about async/await, and ran into a situation where I need to call an async method synchronously. How can I do that? Async method: public async Task<Customers> GetCustomers() { return await Service.GetCustomersAsync(); } Normal usage: public async void GetCustomers() { customerList = await GetCustomers(); } I've tried using the following: Task<Customer&

我将如何同步运行异步任务<T>方法?

我正在学习异步/等待,并遇到了需要同步调用异步方法的情况。 我怎样才能做到这一点? 异步方法: public async Task<Customers> GetCustomers() { return await Service.GetCustomersAsync(); } 正常用法: public async void GetCustomers() { customerList = await GetCustomers(); } 我试过使用以下内容: Task<Customer> task = GetCustomers(); task.Wait() Task<Customer> task = GetC

OpenStreetMap Geocoder other than Nominatim

Are there any other geocoders that are built to use OpenStreetMap data other than Nominatim? I've looked at Nominatim but am unfamiliar with PHP and would like to find or build a geocoder in .Net/ASP that uses OSM data. Would like to find an open source one as a starting point but if there aren't any others is there someone that can explain how it works so I can implement my own. I wou

除Nominatim以外的OpenStreetMap Geocoder

是否还有任何其他地理编码器是为使用Nominatim以外的OpenStreetMap数据而构建的? 我看过Nominatim,但对PHP不熟悉,并希望在使用OSM数据的.Net / ASP中查找或构建地理编码器。 希望找到一个开源的作为起点,但如果没有其他人,有人可以解释它是如何工作的,所以我可以实现我自己的。 我希望它在.NET中,而不是使用PHP版本,所以我可以自定义和扩展它,这是我无法在PHP中完成的。 当我在.Net中工作后,我想开源,因为我没有

InitializeComponent() Cannot locate resource based on system language

The application was developed on machines running windows 10, with the system language set to our local language, danish. Now we are at a stage where the software needs to be used in offices in other countries. However, the view crashes on startup on those machines, and I have found out that if I change the system language on my own machine, it will not work for me either. Why this is, we can&

InitializeComponent()根据系统语言找不到资源

该应用程序是在运行Windows 10的机器上开发的,系统语言设置为我们当地的语言,丹麦语。 现在我们正处于软件需要在其他国家的办公室使用的阶段。 然而,这些机器在启动时崩溃了,我发现如果我在自己的机器上更改系统语言,它也不适用于我。 为什么这是,我们无法弄清楚。 来自InitializeComponent的错误消息: System.IO.IOException:'找不到资源'views / main / mainview.xaml'。' 堆栈跟踪: 在Sy

Shared Memory Key Overflow

I am using a third party library that uses a C# DLL to access resources which in turn uses memory mapping to a C++ runtime. This third party is SkypeKit which is no longer under development. Out of the blue, I received an exception (application ran for days) "Shared Memory Key Overflow" . The stack trace does not provide any of my routines so that I can catch it where it happens and

共享内存密钥溢出

我正在使用第三方库,它使用C#DLL访问资源,然后使用内存映射到C ++运行库。 该第三方是SkypeKit,不再处于开发阶段。 突然之间,我收到了一个异常(应用程序运行了几天) "Shared Memory Key Overflow" 。 堆栈跟踪没有提供任何我的例程,以便我可以在发生的情况下捕获它,并在运行中对其进行修复,而且我目前正在将其作为App代码作为最终方法来捕获异常并正常恢复应用程序。 有没有办法处理这种内存问题,当

Sending Messages between Services in C#

I have 2 Windows services written on .NET 4.5.1. I am looking to see if there is functionality like WinAPI's SendMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam) call that i can use for a GUI-less process like a windows service! Thanks! When two processes need to communicate, they do so using one of any number of inter-process communication (IPC) mechanisms. The answers to t

在C#中的服务之间发送消息

我在.NET 4.5.1上编写了2个Windows服务。 我正在查看是否有像WinAPI的SendMessage(IntPtr hwnd,uint Msg,IntPtr wParam,IntPtr lParam)调用的功能,可以用于像Windows服务这样的无GUI的过程! 谢谢! 当两个进程需要通信时,他们使用任意数量的进程间通信(IPC)机制之一来进行通信。 这个SO帖子的答案给你一些可能性的想法。 为此,我将添加WCF,这是微软推荐的将两个基于.NET的应用程序彼此交谈的方式。 就我个

Loading dll from resources fails

My application depends on a few DLLs. I put them all in resources and than on start of the application I load them using a method I found on the web: public static void LoadDllsFromResources() { AppDomain.CurrentDomain.AssemblyResolve += (sender, a) => { string dllName = a.Name.Contains(',') ? a.Name.Substring(0, a.Name.Inde

从资源加载dll失败

我的应用程序依赖于几个DLL。 我把它们全部放在资源中,而不是在应用程序的开始,我使用我在网上找到的方法加载它们: public static void LoadDllsFromResources() { AppDomain.CurrentDomain.AssemblyResolve += (sender, a) => { string dllName = a.Name.Contains(',') ? a.Name.Substring(0, a.Name.IndexOf(','))

Virtual mouse click c#

I have an multithreaded application that needs to be able to preform multiple mouse click at the same time. I have an IntPtr intptr to a process on which i need to send a mouse click to. I have tried to find this information on the web and there are some examples which i have tried. But I have not got any of them to work. As I understand the correct way to solv my issue is to use the functi

虚拟鼠标点击c#

我有一个多线程应用程序,需要能够同时执行多次鼠标点击。 我有一个IntPtr intptr到我需要发送鼠标点击的进程。 我试图在网上找到这些信息,并且我已经尝试了一些例子。 但我没有得到任何工作。 据我了解,解决我的问题的正确方法是使用函数SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); hWnd是进程的IntPtr。 消息是想要的动作,我想要左键单击, int WM_LBUTTONDBLCLK = 0x0203; IntPtr wParam