{"record":{"id":"dc672fa4a96b49ff","repo":"tui-cs/Terminal.Gui","slug":"functimeprovider-does-not-support-timers-use-virt","errorCode":null,"errorMessage":"FuncTimeProvider does not support timers. Use VirtualTimeProvider for timer support.","messagePattern":"FuncTimeProvider does not support timers\\. Use VirtualTimeProvider for timer support\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Time/FuncTimeProvider.cs","lineNumber":30,"sourceCode":"    ///     Initializes a new instance of the <see cref=\"FuncTimeProvider\"/> class.\n    /// </summary>\n    /// <param name=\"timeFunc\">Function that returns the current time.</param>\n    public FuncTimeProvider (Func<DateTime> timeFunc) { _timeFunc = timeFunc; }\n\n    /// <inheritdoc/>\n    public DateTime Now => _timeFunc ();\n\n    /// <inheritdoc/>\n    public Task Delay (TimeSpan duration, CancellationToken cancellationToken = default)\n    {\n        // For test scenarios, delays complete immediately\n        return Task.CompletedTask;\n    }\n\n    /// <inheritdoc/>\n    public ITimer CreateTimer (TimeSpan interval, Action callback)\n    {\n        throw new NotSupportedException (\"FuncTimeProvider does not support timers. Use VirtualTimeProvider for timer support.\");\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":33,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Time/FuncTimeProvider.cs#L12-L33","documentation":"This error is thrown by FuncTimeProvider.CreateTimer() because FuncTimeProvider is a lightweight test helper that only wraps a Func<DateTime> for time control and does not support timer creation. The error message directs developers to VirtualTimeProvider, which implements a full timer system for test scenarios. FuncTimeProvider is an internal class used only in tests.","triggerScenarios":"Thrown at FuncTimeProvider.cs:30 when CreateTimer(TimeSpan, Action) is called on a FuncTimeProvider instance. This happens when test code attempts to create a timer on a time provider that was constructed via FuncTimeProvider(Func<DateTime>) rather than VirtualTimeProvider. Any component that calls ITimeProvider.CreateTimer will trigger this.","commonSituations":"Writing a test that uses FuncTimeProvider (for simple time control) but the code under test schedules timers (e.g., timeout-based animations, delayed actions, periodic refresh). Mixing FuncTimeProvider with components that require timer support without realizing the limitation.","solutions":["Switch from FuncTimeProvider to VirtualTimeProvider, which supports both time control and timers.","If timers are not needed in the test, mock or avoid the code path that calls CreateTimer.","Review the test to confirm whether timer functionality is required; use VirtualTimeProvider if so.","Check ITimeProvider documentation -- FuncTimeProvider is for time-only scenarios, VirtualTimeProvider for full timer support."],"exampleFix":"// before -- FuncTimeProvider does not support timers\nITimeProvider timeProvider = new FuncTimeProvider(() => DateTime.Now);\n// ... code under test calls timeProvider.CreateTimer(...)\n\n// after -- use VirtualTimeProvider for timer support\nVirtualTimeProvider timeProvider = new VirtualTimeProvider();\n// ... code under test calls timeProvider.CreateTimer(...)\ntimeProvider.Advance(TimeSpan.FromSeconds(1));","handlingStrategy":"validation","validationCode":"// Before creating FuncTimeProvider, check if timers are needed\n// If so, use VirtualTimeProvider instead\nITimeProvider tp = needsTimers ? new VirtualTimeProvider() : new FuncTimeProvider(() => testTime);","typeGuard":"// Check if the provider supports timers before calling CreateTimer\nbool SupportsTimers(ITimeProvider tp) => tp is not FuncTimeProvider;","tryCatchPattern":"try { var timer = timeProvider.CreateTimer(interval, callback); }\ncatch (NotSupportedException ex) { /* switch to VirtualTimeProvider */ }","preventionTips":["Use VirtualTimeProvider instead of FuncTimeProvider when the code under test needs timers.","Check the ITimeProvider documentation -- FuncTimeProvider is time-only, VirtualTimeProvider is full-featured.","If unsure, default to VirtualTimeProvider in tests.","FuncTimeProvider is internal; it should only appear in test code."],"tags":["testing","time","timer","test-infrastructure"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}